Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): Select Menus v2 #1560

Merged
merged 8 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions examples/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bot.on("messageCreate", (msg) => { // When a message is created
content: "Button Example",
components: [
{
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 1 select menu per action row
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 5 buttons per action row
components: [
{
type: Constants.ComponentTypes.BUTTON, // https://discord.com/developers/docs/interactions/message-components#buttons
Expand All @@ -40,10 +40,10 @@ bot.on("messageCreate", (msg) => { // When a message is created
content: "Select Menu Example",
components: [
{
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 5 buttons per action row
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 1 select menu per action row
components: [
{
type: Constants.ComponentTypes.SELECT_MENU, // https://discord.com/developers/docs/interactions/message-components#select-menus
type: Constants.ComponentTypes.STRING_SELECT, // https://discord.com/developers/docs/interactions/message-components#select-menus
custom_id: "select_one",
placeholder: "Select an option",
options: [ // The options to select from https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
Expand All @@ -64,6 +64,26 @@ bot.on("messageCreate", (msg) => { // When a message is created
},
],
},
{
type: Constants.ComponentTypes.ACTION_ROW, // You can have up to 5 action rows, and 1 select menu per action row
components: [
{
type: Constants.ComponentTypes.CHANNEL_SELECT, // https://discord.com/developers/docs/interactions/message-components#select-menus
custom_id: "select_two",
channel_types: [Constants.ChannelTypes.GUILD_TEXT, Constants.ChannelTypes.GUILD_VOICE], // types of channels that can be selected
placeholder: "Select a channel",
default_values: [ // List of default values for auto-populated select menus https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure
{
id: "[Insert default channel id here]",
type: "channel"
}
],
min_values: 1,
max_values: 1,
disabled: false, // Whether or not the select menu is disabled, is false by default
},
],
},
],
});
// Send a message in the same channel with a Select Menu
Expand Down
42 changes: 32 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ declare namespace Eris {
type PollLayoutTypes = Constants["PollLayoutTypes"][keyof Constants["PollLayoutTypes"]];
type PossiblyUncachedMessage = Message | { channel: TextableChannel | { id: string; guild?: Uncached }; guildID?: string; id: string };
type ReactionTypes = Constants["ReactionTypes"][keyof Constants["ReactionTypes"]];
type SelectMenu = StringSelectMenu | ChannelSelectMenu | ResolvedSelectMenus;
type SelectMenuNonResolvedTypes = Constants["ComponentTypes"][keyof Pick<Constants["ComponentTypes"], "STRING_SELECT">];
type SelectMenuResolvedTypes = Constants["ComponentTypes"][keyof Pick<Constants["ComponentTypes"], "USER_SELECT" | "ROLE_SELECT" | "MENTIONABLE_SELECT" | "CHANNEL_SELECT">];
type SelectMenuTypes = SelectMenuNonResolvedTypes | SelectMenuResolvedTypes;

// Permission
type PermissionType = Constants["PermissionOverwriteTypes"][keyof Constants["PermissionOverwriteTypes"]];
Expand Down Expand Up @@ -1351,21 +1355,18 @@ declare namespace Eris {
resolved?: CommandInteractionResolvedData;
options?: InteractionDataOptions[];
}
interface CommandInteractionResolvedData {
channels?: Collection<AnyChannel>;
members?: Collection<Member>;
interface CommandInteractionResolvedData extends InteractionResolvedData {
messages?: Collection<Message>;
roles?: Collection<Role>;
users?: Collection<User>;
}
interface ComponentInteractionButtonData {
component_type: Constants["ComponentTypes"]["BUTTON"];
custom_id: string;
}
interface ComponentInteractionSelectMenuData {
component_type: Constants["ComponentTypes"]["SELECT_MENU"];
component_type: SelectMenuTypes;
custom_id: string;
values: string[];
resolved?: InteractionResolvedData;
}
interface InteractionAutocomplete {
choices: ApplicationCommandOptionChoice[];
Expand Down Expand Up @@ -1395,6 +1396,12 @@ declare namespace Eris {
data?: InteractionCallbackData;
type: InteractionResponseTypes;
}
interface InteractionResolvedData {
channels?: Collection<AnyChannel>;
members?: Collection<Member>;
roles?: Collection<Role>;
users?: Collection<User>;
}

// Invite
interface CreateChannelInviteOptions extends CreateInviteOptions {
Expand Down Expand Up @@ -1652,22 +1659,37 @@ declare namespace Eris {
burst: number;
normal: number;
}
interface SelectMenu {
interface SelectMenuBase {
custom_id: string;
disabled?: boolean;
max_values?: number;
min_values?: number;
options: SelectMenuOptions[];
placeholder?: string;
type: Constants["ComponentTypes"]["SELECT_MENU"];
type: SelectMenuTypes;
}
interface ChannelSelectMenu extends SelectMenuBase {
channel_types?: ChannelTypes[];
type: Constants["ComponentTypes"]["CHANNEL_SELECT"];
}
interface StringSelectMenu extends SelectMenuBase {
options: StringSelectOptions[];
type: Constants["ComponentTypes"]["STRING_SELECT"];
}
interface SelectMenuOptions {
interface StringSelectOptions {
default?: boolean;
description?: string;
emoji?: Partial<PartialEmoji>;
label: string;
value: string;
}
interface ResolvedSelectMenus extends SelectMenuBase {
default_values?: SelectDefaultValues[];
type: SelectMenuResolvedTypes;
}
interface SelectDefaultValues {
id: string;
type: "user" | "role" | "channel";
}
interface Sticker extends StickerItems {
/** @deprecated */
asset: "";
Expand Down
Loading