diff --git a/src/structures/Message.js b/src/structures/Message.js index 99e4543..6e8e746 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -11,6 +11,7 @@ const MessageButton = require('./MessageButton'); const Embed = require('./MessageEmbed'); const Mentions = require('./MessageMentions'); const MessagePayload = require('./MessagePayload'); +const MessageSelectMenu = require('./MessageSelectMenu'); const ReactionCollector = require('./ReactionCollector'); const { Sticker } = require('./Sticker'); const { Error } = require('../errors'); @@ -1089,26 +1090,43 @@ class Message extends Base { clickButton(button) { if (!button) { button = this.components.flatMap(row => row.components).find(b => b.type === 'BUTTON')?.customId; - } - if (button instanceof MessageButton) { + } else if (button instanceof MessageButton) { button = button.customId; - } - if (typeof button === 'object') { + } else if (typeof button === 'object') { if (!('row' in button) || !('col' in button)) throw new TypeError('INVALID_BUTTON_LOCATION'); button = this.components[button.row]?.components[button.col]?.customId; } + if (!button) throw new TypeError('BUTTON_NOT_FOUND'); button = this.components.flatMap(row => row.components).find(b => b.customId === button && b.type === 'BUTTON'); return button ? button.click(this) : Promise.reject(new TypeError('BUTTON_NOT_FOUND')); } /** * Select specific menu or First Menu - * @param {string|number|Array} menuID Select Menu specific id or row / auto select first Menu - * @param {Array} options Menu Options + * @param {MessageSelectMenu|string|number|Array} menuID MenuId / MessageSelectMenu / Row of Menu / Array of Values (first menu) + * @param {Array} options Array of Values * @returns {Promise} + * @example + * client.on('messageCreate', async message => { + * if (message.components.length) { + * // Row + * await message.selectMenu(1, [message.channel]); // row 1, type: Channel, multi: false + * // Id + * await message.selectMenu('menu-id', ['uid1', client.user, message.member]); // MenuId, type: User, multi: true + * // First Menu + * await message.selectMenu(['role-id']); // First Menu, type: role, multi: false + * // class MessageSelectMenu + * const menu = message.components[0].components[0]; + * await message.selectMenu(menu, ['option1', 'option2']); + * // MessageSelectMenu (2) + * menu.select(message, ['option1', 'option2']); + * } + * }); */ selectMenu(menuID, options = []) { if (!this.components[0]) throw new TypeError('MESSAGE_NO_COMPONENTS'); - if (/[0-4]/.test(menuID)) { + if (menuID instanceof MessageSelectMenu) { + // + } else if (/[0-4]/.test(menuID)) { menuID = this.components[menuID]?.components[0]; } else { const menuAll = this.components diff --git a/src/util/MessageFlags.js b/src/util/MessageFlags.js index b91a1fc..ff50e2d 100644 --- a/src/util/MessageFlags.js +++ b/src/util/MessageFlags.js @@ -31,6 +31,7 @@ class MessageFlags extends BitField {} * * `HAS_THREAD` * * `EPHEMERAL` * * `LOADING` + * * `FAILED_TO_MENTION_SOME_ROLES_IN_THREAD` * @type {Object} * @see {@link https://discord.com/developers/docs/resources/channel#message-object-message-flags} */ @@ -43,6 +44,7 @@ MessageFlags.FLAGS = { HAS_THREAD: 1 << 5, EPHEMERAL: 1 << 6, LOADING: 1 << 7, + FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 1 << 8, }; module.exports = MessageFlags; diff --git a/src/util/Options.js b/src/util/Options.js index 24edc6c..72c8e8f 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -195,7 +195,7 @@ class Options extends null { referrer_current: 'https://discord.com/channels/@me', referring_domain_current: 'discord.com', release_channel: 'stable', - client_build_number: 160771, + client_build_number: 162224, client_event_source: null, }, // ! capabilities: 4093, diff --git a/typings/index.d.ts b/typings/index.d.ts index 24ac40d..71e5657 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1975,7 +1975,7 @@ export class Message extends Base { public markUnread(): Promise; public markRead(): Promise; public clickButton(button?: MessageButton | MessageButtonLocation | string): Promise; - public selectMenu(menuID: string, options: any[]): Promise; + public selectMenu(menuID: MessageSelectMenu|Snowflake|number, options: any[]): Promise; public selectMenu(options: any[]): Promise; public contextMenu(botID: Snowflake, commandName: string): Promise; } @@ -4954,7 +4954,9 @@ export type ApplicationFlagsString = | 'VERIFICATION_PENDING_GUILD_LIMIT' | 'EMBEDDED' | 'GATEWAY_MESSAGE_CONTENT' - | 'GATEWAY_MESSAGE_CONTENT_LIMITED'; + | 'GATEWAY_MESSAGE_CONTENT_LIMITED' + | 'EMBEDDED_FIRST_PARTY' + | 'APPLICATION_COMMAND_BADGE'; export interface AuditLogChange { key: APIAuditLogChange['key']; @@ -6229,7 +6231,8 @@ export type MessageFlagsString = | 'URGENT' | 'HAS_THREAD' | 'EPHEMERAL' - | 'LOADING'; + | 'LOADING' + | 'FAILED_TO_MENTION_SOME_ROLES_IN_THREAD'; export interface MessageInteraction { id: Snowflake;