diff --git a/src/structures/Message.js b/src/structures/Message.js index 543340c..ce03c66 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -8,6 +8,7 @@ const BaseMessageComponent = require('./BaseMessageComponent'); const ClientApplication = require('./ClientApplication'); const InteractionCollector = require('./InteractionCollector'); const MessageAttachment = require('./MessageAttachment'); +const MessageButton = require('./MessageButton'); const Embed = require('./MessageEmbed'); const Mentions = require('./MessageMentions'); const MessagePayload = require('./MessagePayload'); @@ -1029,33 +1030,26 @@ class Message extends Base { } /** - * Click specific button [Suggestion: Dux#2925] - * @param {string} buttonID Button ID + * Click specific button + * @param {MessageButton|string} button Button ID * @returns {Promise} */ - async clickButton(buttonID) { - if (typeof buttonID !== 'string') { + clickButton(button) { + let buttonID; + if (button instanceof MessageButton) button = button.customId; + if (typeof button === 'string') buttonID = button; + if (!buttonID) { throw new TypeError('BUTTON_ID_NOT_STRING'); } if (!this.components[0]) throw new TypeError('MESSAGE_NO_COMPONENTS'); - let button; - await Promise.all( - this.components.map(async row => { - await Promise.all( - row.components.map(interactionComponent => { - if (interactionComponent.type == 'BUTTON' && interactionComponent.customId == buttonID) { - button = interactionComponent; - } - return true; - }), - ); - }), - ); - if (!button) { - throw new TypeError('BUTTON_NOT_FOUND'); - } else { - return button.click(this); + for (const components of this.components) { + for (const interactionComponent of components.components) { + if (interactionComponent.type == 'BUTTON' && interactionComponent.customId == buttonID) { + return interactionComponent.click(this); + } + } } + throw new TypeError('BUTTON_NOT_FOUND'); } /** * Select specific menu or First Menu diff --git a/typings/index.d.ts b/typings/index.d.ts index d6f645a..45466a9 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1929,7 +1929,7 @@ export class Message extends Base { // Added public markUnread(): Promise; public markRead(): Promise; - public clickButton(buttonID: string): Promise; + public clickButton(button: MessageButton | string): Promise; public selectMenu(menuID: string, options: string[]): Promise; public selectMenu(options: string[]): Promise; public contextMenu(botID: Snowflake, commandName: string): Promise;