feat: Add new flags, new option for Message#selectMenu

This commit is contained in:
March 7th 2022-12-04 01:46:40 +07:00
parent 720848131d
commit 7d34a5de24
4 changed files with 34 additions and 11 deletions

View File

@ -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<string>} menuID Select Menu specific id or row / auto select first Menu
* @param {Array<any>} options Menu Options
* @param {MessageSelectMenu|string|number|Array<any>} menuID MenuId / MessageSelectMenu / Row of Menu / Array of Values (first menu)
* @param {Array<any>} options Array of Values
* @returns {Promise<InteractionResponse>}
* @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

View File

@ -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;

View File

@ -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,

9
typings/index.d.ts vendored
View File

@ -1975,7 +1975,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public markUnread(): Promise<boolean>;
public markRead(): Promise<boolean>;
public clickButton(button?: MessageButton | MessageButtonLocation | string): Promise<InteractionResponse>;
public selectMenu(menuID: string, options: any[]): Promise<InteractionResponse>;
public selectMenu(menuID: MessageSelectMenu|Snowflake|number, options: any[]): Promise<InteractionResponse>;
public selectMenu(options: any[]): Promise<InteractionResponse>;
public contextMenu(botID: Snowflake, commandName: string): Promise<InteractionResponse>;
}
@ -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;