refactor(Interaction): See description
- Change the data returned when interacting, from `nonce: Snowflake` to `data: InteractionResponseBody` (use try catch to detect command errors) - Full support for Autocomplete (Automatically selects the first option)
This commit is contained in:
parent
ec809a0f95
commit
1a6b3addfe
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js-selfbot-v13",
|
"name": "discord.js-selfbot-v13",
|
||||||
"version": "2.3.71",
|
"version": "2.3.72",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord.js-selfbot-v13",
|
"name": "discord.js-selfbot-v13",
|
||||||
"version": "2.3.71",
|
"version": "2.3.72",
|
||||||
"license": "GNU General Public License v3.0",
|
"license": "GNU General Public License v3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aikochan2k6/qrcode-terminal": "^0.12.0",
|
"@aikochan2k6/qrcode-terminal": "^0.12.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js-selfbot-v13",
|
"name": "discord.js-selfbot-v13",
|
||||||
"version": "2.3.71",
|
"version": "2.3.72",
|
||||||
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
|
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"types": "./typings/index.d.ts",
|
"types": "./typings/index.d.ts",
|
||||||
@ -17,7 +17,7 @@
|
|||||||
"lint:all": "npm run lint && npm run lint:typings",
|
"lint:all": "npm run lint && npm run lint:typings",
|
||||||
"docs": "docgen --source src --custom docs/index.yml --output docs/main.json",
|
"docs": "docgen --source src --custom docs/index.yml --output docs/main.json",
|
||||||
"docs:test": "docgen --source src --custom docs/index.yml",
|
"docs:test": "docgen --source src --custom docs/index.yml",
|
||||||
"build": "npm i && npm run lint:fix && npm run lint:typings:fix && npm run format && npm run docs"
|
"build": "npm run lint:fix && npm run lint:typings:fix && npm run format && npm run docs"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
|
@ -19,5 +19,5 @@ module.exports = (client, { d: data }) => {
|
|||||||
* @param {AutocompleteResponse} data Data
|
* @param {AutocompleteResponse} data Data
|
||||||
* @deprecated Test only
|
* @deprecated Test only
|
||||||
*/
|
*/
|
||||||
client.emit(Events.DEBUG, data);
|
client.emit(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, data);
|
||||||
};
|
};
|
||||||
|
@ -8,6 +8,9 @@ const { Events } = require('../../../util/Constants');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = (client, packet) => {
|
module.exports = (client, packet) => {
|
||||||
if (client.user.bot) client.actions.InteractionCreate.handle(packet.d);
|
if (client.user.bot) {
|
||||||
else client.emit(Events.INTERACTION_CREATE, packet.d);
|
client.actions.InteractionCreate.handle(packet.d);
|
||||||
|
} else {
|
||||||
|
client.emit(Events.INTERACTION_CREATE, packet.d);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -8,4 +8,8 @@ module.exports = (client, { d: data }) => {
|
|||||||
* @param {InteractionResponseBody} data data
|
* @param {InteractionResponseBody} data data
|
||||||
*/
|
*/
|
||||||
client.emit(Events.INTERACTION_FAILURE, data);
|
client.emit(Events.INTERACTION_FAILURE, data);
|
||||||
|
client.emit('interactionResponse', {
|
||||||
|
status: false,
|
||||||
|
metadata: data,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -8,4 +8,8 @@ module.exports = (client, { d: data }) => {
|
|||||||
* @param {InteractionResponseBody} data data
|
* @param {InteractionResponseBody} data data
|
||||||
*/
|
*/
|
||||||
client.emit(Events.INTERACTION_SUCCESS, data);
|
client.emit(Events.INTERACTION_SUCCESS, data);
|
||||||
|
client.emit('interactionResponse', {
|
||||||
|
status: true,
|
||||||
|
metadata: data,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@ const handlers = Object.fromEntries([
|
|||||||
['RESUMED', require('./RESUMED')],
|
['RESUMED', require('./RESUMED')],
|
||||||
['RELATIONSHIP_ADD', require('./RELATIONSHIP_ADD')],
|
['RELATIONSHIP_ADD', require('./RELATIONSHIP_ADD')],
|
||||||
['RELATIONSHIP_REMOVE', require('./RELATIONSHIP_REMOVE')],
|
['RELATIONSHIP_REMOVE', require('./RELATIONSHIP_REMOVE')],
|
||||||
|
['APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE', require('./APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE')],
|
||||||
['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')],
|
['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')],
|
||||||
['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')],
|
['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')],
|
||||||
['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')],
|
['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')],
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { setTimeout } = require('node:timers');
|
||||||
const Base = require('./Base');
|
const Base = require('./Base');
|
||||||
const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');
|
const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');
|
||||||
const MessageAttachment = require('../structures/MessageAttachment');
|
const MessageAttachment = require('../structures/MessageAttachment');
|
||||||
const { ApplicationCommandOptionTypes, ApplicationCommandTypes, ChannelTypes } = require('../util/Constants');
|
const { ApplicationCommandOptionTypes, ApplicationCommandTypes, ChannelTypes, Events } = require('../util/Constants');
|
||||||
const DataResolver = require('../util/DataResolver');
|
const DataResolver = require('../util/DataResolver');
|
||||||
const Permissions = require('../util/Permissions');
|
const Permissions = require('../util/Permissions');
|
||||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||||
@ -589,7 +590,7 @@ class ApplicationCommand extends Base {
|
|||||||
* Send Slash command to channel
|
* Send Slash command to channel
|
||||||
* @param {Message} message Discord Message
|
* @param {Message} message Discord Message
|
||||||
* @param {Array<string>} options The options to Slash Command
|
* @param {Array<string>} options The options to Slash Command
|
||||||
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async sendSlashCommand(message, options = []) {
|
async sendSlashCommand(message, options = []) {
|
||||||
// Check Options
|
// Check Options
|
||||||
@ -632,6 +633,66 @@ class ApplicationCommand extends Base {
|
|||||||
} else {
|
} else {
|
||||||
option_ = optionFormat;
|
option_ = optionFormat;
|
||||||
}
|
}
|
||||||
|
// Autoresponse
|
||||||
|
const getAutoResponse = async (options_, type, name, value) => {
|
||||||
|
const op = Array.from(options_);
|
||||||
|
op.push({
|
||||||
|
type,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
focused: true,
|
||||||
|
});
|
||||||
|
let nonce = SnowflakeUtil.generate();
|
||||||
|
const data = {
|
||||||
|
type: 4, // Auto-complete
|
||||||
|
application_id: this.applicationId,
|
||||||
|
guild_id: message.guildId,
|
||||||
|
channel_id: message.channelId,
|
||||||
|
session_id: this.client.session_id,
|
||||||
|
data: {
|
||||||
|
// ApplicationCommandData
|
||||||
|
version: this.version,
|
||||||
|
id: this.id,
|
||||||
|
name: this.name,
|
||||||
|
type: ApplicationCommandTypes[this.type],
|
||||||
|
options: op,
|
||||||
|
attachments: attachments,
|
||||||
|
},
|
||||||
|
nonce,
|
||||||
|
};
|
||||||
|
await this.client.api.interactions
|
||||||
|
.post({
|
||||||
|
data,
|
||||||
|
files: attachmentsBuffer,
|
||||||
|
})
|
||||||
|
.catch(async () => {
|
||||||
|
nonce = SnowflakeUtil.generate();
|
||||||
|
data.data.guild_id = message.guildId;
|
||||||
|
data.nonce = nonce;
|
||||||
|
await this.client.api.interactions.post({
|
||||||
|
data,
|
||||||
|
files: attachmentsBuffer,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const handler = data => {
|
||||||
|
timeout.refresh();
|
||||||
|
if (data.nonce !== nonce) return;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
this.client.removeListener(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, handler);
|
||||||
|
this.client.decrementMaxListeners();
|
||||||
|
if (data.choices.length > 1) resolve(data.choices[0].value);
|
||||||
|
else resolve(value);
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
this.client.removeListener(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, handler);
|
||||||
|
this.client.decrementMaxListeners();
|
||||||
|
resolve(value);
|
||||||
|
}, 15_000).unref();
|
||||||
|
this.client.incrementMaxListeners();
|
||||||
|
this.client.on(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, handler);
|
||||||
|
});
|
||||||
|
};
|
||||||
for (i; i < options.length; i++) {
|
for (i; i < options.length; i++) {
|
||||||
const value = options[i];
|
const value = options[i];
|
||||||
if (!subCommandCheck && !this?.options[i]) continue;
|
if (!subCommandCheck && !this?.options[i]) continue;
|
||||||
@ -663,6 +724,13 @@ class ApplicationCommand extends Base {
|
|||||||
? Number(value)
|
? Number(value)
|
||||||
: this.options[i].type == 'BOOLEAN'
|
: this.options[i].type == 'BOOLEAN'
|
||||||
? Boolean(value)
|
? Boolean(value)
|
||||||
|
: this.options[i].autocomplete
|
||||||
|
? await getAutoResponse(
|
||||||
|
optionFormat,
|
||||||
|
ApplicationCommandOptionTypes[this.options[i].type],
|
||||||
|
this.options[i].name,
|
||||||
|
value,
|
||||||
|
)
|
||||||
: value),
|
: value),
|
||||||
};
|
};
|
||||||
optionFormat.push(data);
|
optionFormat.push(data);
|
||||||
@ -696,6 +764,13 @@ class ApplicationCommand extends Base {
|
|||||||
? Number(value)
|
? Number(value)
|
||||||
: subCommand.options[i].type == 'BOOLEAN'
|
: subCommand.options[i].type == 'BOOLEAN'
|
||||||
? Boolean(value)
|
? Boolean(value)
|
||||||
|
: this.options[i].autocomplete
|
||||||
|
? await getAutoResponse(
|
||||||
|
optionFormat,
|
||||||
|
ApplicationCommandOptionTypes[subCommand.options[i].type],
|
||||||
|
subCommand.options[i].name,
|
||||||
|
value,
|
||||||
|
)
|
||||||
: value),
|
: value),
|
||||||
};
|
};
|
||||||
optionFormat.push(data);
|
optionFormat.push(data);
|
||||||
@ -740,13 +815,30 @@ class ApplicationCommand extends Base {
|
|||||||
files: attachmentsBuffer,
|
files: attachmentsBuffer,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return nonce;
|
return new Promise((resolve, reject) => {
|
||||||
|
const handler = data => {
|
||||||
|
timeout.refresh();
|
||||||
|
if (data.metadata.nonce !== nonce) return;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
this.client.removeListener('interactionResponse', handler);
|
||||||
|
this.client.decrementMaxListeners();
|
||||||
|
if (data.status) resolve(data.metadata);
|
||||||
|
else reject(data.metadata);
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
this.client.removeListener('interactionResponse', handler);
|
||||||
|
this.client.decrementMaxListeners();
|
||||||
|
reject(new Error('INTERACTION_TIMEOUT'));
|
||||||
|
}, 15_000).unref();
|
||||||
|
this.client.incrementMaxListeners();
|
||||||
|
this.client.on('interactionResponse', handler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Message Context Menu
|
* Message Context Menu
|
||||||
* @param {Message} message Discord Message
|
* @param {Message} message Discord Message
|
||||||
* @param {boolean} sendFromMessage nothing .-. not used
|
* @param {boolean} sendFromMessage nothing .-. not used
|
||||||
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async sendContextMenu(message, sendFromMessage = false) {
|
async sendContextMenu(message, sendFromMessage = false) {
|
||||||
if (!sendFromMessage && !(message instanceof Message())) {
|
if (!sendFromMessage && !(message instanceof Message())) {
|
||||||
@ -772,7 +864,24 @@ class ApplicationCommand extends Base {
|
|||||||
nonce,
|
nonce,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return nonce;
|
return new Promise((resolve, reject) => {
|
||||||
|
const handler = data => {
|
||||||
|
timeout.refresh();
|
||||||
|
if (data.metadata.nonce !== nonce) return;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
this.client.removeListener('interactionResponse', handler);
|
||||||
|
this.client.decrementMaxListeners();
|
||||||
|
if (data.status) resolve(data.metadata);
|
||||||
|
else reject(data.metadata);
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
this.client.removeListener('interactionResponse', handler);
|
||||||
|
this.client.decrementMaxListeners();
|
||||||
|
reject(new Error('INTERACTION_TIMEOUT'));
|
||||||
|
}, 15_000).unref();
|
||||||
|
this.client.incrementMaxListeners();
|
||||||
|
this.client.on('interactionResponse', handler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1017,7 +1017,7 @@ class Message extends Base {
|
|||||||
/**
|
/**
|
||||||
* Click specific button [Suggestion: Dux#2925]
|
* Click specific button [Suggestion: Dux#2925]
|
||||||
* @param {string<Button.customId>} buttonID Button ID
|
* @param {string<Button.customId>} buttonID Button ID
|
||||||
* @returns {Promise<pending>}
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async clickButton(buttonID) {
|
async clickButton(buttonID) {
|
||||||
if (typeof buttonID !== 'string') {
|
if (typeof buttonID !== 'string') {
|
||||||
@ -1040,17 +1040,14 @@ class Message extends Base {
|
|||||||
if (!button) {
|
if (!button) {
|
||||||
throw new TypeError('BUTTON_NOT_FOUND');
|
throw new TypeError('BUTTON_NOT_FOUND');
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line no-async-promise-executor
|
return button.click(this);
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
const res = await button.click(this).catch(reject);
|
|
||||||
if (res) resolve(res);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Select specific menu or First Menu
|
* Select specific menu or First Menu
|
||||||
* @param {string|Array<string>} menuID Select Menu specific id or auto select first Menu
|
* @param {string|Array<string>} menuID Select Menu specific id or auto select first Menu
|
||||||
* @param {Array<string>} options Menu Options
|
* @param {Array<string>} options Menu Options
|
||||||
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async selectMenu(menuID, options = []) {
|
async selectMenu(menuID, options = []) {
|
||||||
if (!this.components[0]) throw new TypeError('MESSAGE_NO_COMPONENTS');
|
if (!this.components[0]) throw new TypeError('MESSAGE_NO_COMPONENTS');
|
||||||
@ -1077,18 +1074,14 @@ class Message extends Base {
|
|||||||
else if (typeof menuID !== 'string') throw new TypeError('MENU_ID_NOT_STRING');
|
else if (typeof menuID !== 'string') throw new TypeError('MENU_ID_NOT_STRING');
|
||||||
else throw new TypeError('MENU_ID_NOT_FOUND');
|
else throw new TypeError('MENU_ID_NOT_FOUND');
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-async-promise-executor
|
return menuCorrect.select(this, Array.isArray(menuID) ? menuID : options);
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
const res = await menuCorrect.select(this, Array.isArray(menuID) ? menuID : options).catch(reject);
|
|
||||||
if (res) resolve(res);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
/**
|
/**
|
||||||
* Send context Menu v2
|
* Send context Menu v2
|
||||||
* @param {Snowflake} botId Bot id
|
* @param {Snowflake} botId Bot id
|
||||||
* @param {string} commandName Command name in Context Menu
|
* @param {string} commandName Command name in Context Menu
|
||||||
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async contextMenu(botId, commandName) {
|
async contextMenu(botId, commandName) {
|
||||||
if (!botId) throw new Error('Bot ID is required');
|
if (!botId) throw new Error('Bot ID is required');
|
||||||
@ -1124,8 +1117,7 @@ class Message extends Base {
|
|||||||
.join(', ')}`,
|
.join(', ')}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const nonce = await contextCMD.sendContextMenu(this, true);
|
return contextCMD.sendContextMenu(this, true);
|
||||||
return nonce;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { setTimeout } = require('node:timers');
|
||||||
const BaseMessageComponent = require('./BaseMessageComponent');
|
const BaseMessageComponent = require('./BaseMessageComponent');
|
||||||
const { Message } = require('./Message');
|
const { Message } = require('./Message');
|
||||||
const { RangeError } = require('../errors');
|
const { RangeError } = require('../errors');
|
||||||
@ -166,7 +167,7 @@ class MessageButton extends BaseMessageComponent {
|
|||||||
/**
|
/**
|
||||||
* Click the button
|
* Click the button
|
||||||
* @param {Message} message Discord Message
|
* @param {Message} message Discord Message
|
||||||
* @returns {Promise<Snowflake>}
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async click(message) {
|
async click(message) {
|
||||||
const nonce = SnowflakeUtil.generate();
|
const nonce = SnowflakeUtil.generate();
|
||||||
@ -188,7 +189,24 @@ class MessageButton extends BaseMessageComponent {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return nonce;
|
return new Promise((resolve, reject) => {
|
||||||
|
const handler = data => {
|
||||||
|
timeout.refresh();
|
||||||
|
if (data.metadata.nonce !== nonce) return;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
this.message.client.removeListener('interactionResponse', handler);
|
||||||
|
this.message.client.decrementMaxListeners();
|
||||||
|
if (data.status) resolve(data.metadata);
|
||||||
|
else reject(data.metadata);
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
this.message.client.removeListener('interactionResponse', handler);
|
||||||
|
this.message.client.decrementMaxListeners();
|
||||||
|
reject(new Error('INTERACTION_TIMEOUT'));
|
||||||
|
}, 15_000).unref();
|
||||||
|
this.message.client.incrementMaxListeners();
|
||||||
|
this.message.client.on('interactionResponse', handler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { setTimeout } = require('node:timers');
|
||||||
const BaseMessageComponent = require('./BaseMessageComponent');
|
const BaseMessageComponent = require('./BaseMessageComponent');
|
||||||
const { Message } = require('./Message');
|
const { Message } = require('./Message');
|
||||||
const { MessageComponentTypes } = require('../util/Constants');
|
const { MessageComponentTypes } = require('../util/Constants');
|
||||||
@ -214,7 +215,7 @@ class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
* Mesage select menu
|
* Mesage select menu
|
||||||
* @param {Message} message The message this select menu is for
|
* @param {Message} message The message this select menu is for
|
||||||
* @param {Array<string>} values The values of the select menu
|
* @param {Array<string>} values The values of the select menu
|
||||||
* @returns {Promise<Snowflake>}
|
* @returns {Promise<InteractionResponseBody>}
|
||||||
*/
|
*/
|
||||||
async select(message, values = []) {
|
async select(message, values = []) {
|
||||||
// Github copilot is the best :))
|
// Github copilot is the best :))
|
||||||
@ -259,7 +260,24 @@ class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
nonce,
|
nonce,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return nonce;
|
return new Promise((resolve, reject) => {
|
||||||
|
const handler = data => {
|
||||||
|
timeout.refresh();
|
||||||
|
if (data.metadata.nonce !== nonce) return;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
this.message.client.removeListener('interactionResponse', handler);
|
||||||
|
this.message.client.decrementMaxListeners();
|
||||||
|
if (data.status) resolve(data.metadata);
|
||||||
|
else reject(data.metadata);
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
this.message.client.removeListener('interactionResponse', handler);
|
||||||
|
this.message.client.decrementMaxListeners();
|
||||||
|
reject(new Error('INTERACTION_TIMEOUT'));
|
||||||
|
}, 15_000).unref();
|
||||||
|
this.message.client.incrementMaxListeners();
|
||||||
|
this.message.client.on('interactionResponse', handler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +258,7 @@ exports.Opcodes = {
|
|||||||
* * API_RESPONSE: apiResponse
|
* * API_RESPONSE: apiResponse
|
||||||
* * API_REQUEST: apiRequest
|
* * API_REQUEST: apiRequest
|
||||||
* * CLIENT_READY: ready
|
* * CLIENT_READY: ready
|
||||||
|
* * APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE: applicationCommandAutocompleteResponse
|
||||||
* * APPLICATION_COMMAND_CREATE: applicationCommandCreate (deprecated)
|
* * APPLICATION_COMMAND_CREATE: applicationCommandCreate (deprecated)
|
||||||
* * APPLICATION_COMMAND_DELETE: applicationCommandDelete (deprecated)
|
* * APPLICATION_COMMAND_DELETE: applicationCommandDelete (deprecated)
|
||||||
* * APPLICATION_COMMAND_UPDATE: applicationCommandUpdate (deprecated)
|
* * APPLICATION_COMMAND_UPDATE: applicationCommandUpdate (deprecated)
|
||||||
@ -336,6 +337,7 @@ exports.Events = {
|
|||||||
API_RESPONSE: 'apiResponse',
|
API_RESPONSE: 'apiResponse',
|
||||||
API_REQUEST: 'apiRequest',
|
API_REQUEST: 'apiRequest',
|
||||||
CLIENT_READY: 'ready',
|
CLIENT_READY: 'ready',
|
||||||
|
APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE: 'applicationCommandAutocompleteResponse',
|
||||||
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate',
|
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate',
|
||||||
APPLICATION_COMMAND_DELETE: 'applicationCommandDelete',
|
APPLICATION_COMMAND_DELETE: 'applicationCommandDelete',
|
||||||
APPLICATION_COMMAND_UPDATE: 'applicationCommandUpdate',
|
APPLICATION_COMMAND_UPDATE: 'applicationCommandUpdate',
|
||||||
@ -454,6 +456,7 @@ exports.PartialTypes = keyMirror(['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE',
|
|||||||
* The type of a WebSocket message event, e.g. `MESSAGE_CREATE`. Here are the available events:
|
* The type of a WebSocket message event, e.g. `MESSAGE_CREATE`. Here are the available events:
|
||||||
* * READY
|
* * READY
|
||||||
* * RESUMED
|
* * RESUMED
|
||||||
|
* * APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE
|
||||||
* * APPLICATION_COMMAND_CREATE (deprecated)
|
* * APPLICATION_COMMAND_CREATE (deprecated)
|
||||||
* * APPLICATION_COMMAND_DELETE (deprecated)
|
* * APPLICATION_COMMAND_DELETE (deprecated)
|
||||||
* * APPLICATION_COMMAND_UPDATE (deprecated)
|
* * APPLICATION_COMMAND_UPDATE (deprecated)
|
||||||
@ -513,6 +516,7 @@ exports.PartialTypes = keyMirror(['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE',
|
|||||||
exports.WSEvents = keyMirror([
|
exports.WSEvents = keyMirror([
|
||||||
'READY',
|
'READY',
|
||||||
'RESUMED',
|
'RESUMED',
|
||||||
|
'APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE',
|
||||||
'APPLICATION_COMMAND_CREATE',
|
'APPLICATION_COMMAND_CREATE',
|
||||||
'APPLICATION_COMMAND_DELETE',
|
'APPLICATION_COMMAND_DELETE',
|
||||||
'APPLICATION_COMMAND_UPDATE',
|
'APPLICATION_COMMAND_UPDATE',
|
||||||
|
20
typings/index.d.ts
vendored
20
typings/index.d.ts
vendored
@ -1866,10 +1866,10 @@ export class Message<Cached extends boolean = boolean> extends Base {
|
|||||||
public inGuild(): this is Message<true> & this;
|
public inGuild(): this is Message<true> & this;
|
||||||
// Added
|
// Added
|
||||||
public markUnread(): Promise<boolean>;
|
public markUnread(): Promise<boolean>;
|
||||||
public clickButton(buttonID: string): Promise<Snowflake>;
|
public clickButton(buttonID: string): Promise<InteractionResponseBody>;
|
||||||
public selectMenu(menuID: string, options: string[]): Promise<Snowflake>;
|
public selectMenu(menuID: string, options: string[]): Promise<InteractionResponseBody>;
|
||||||
public selectMenu(options: string[]): Promise<Snowflake>;
|
public selectMenu(options: string[]): Promise<InteractionResponseBody>;
|
||||||
public contextMenu(botID: Snowflake, commandName: string): Promise<Snowflake>;
|
public contextMenu(botID: Snowflake, commandName: string): Promise<InteractionResponseBody>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MessageActionRow<
|
export class MessageActionRow<
|
||||||
@ -1911,6 +1911,11 @@ export class MessageAttachment {
|
|||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface InteractionResponseBody {
|
||||||
|
id: Snowflake;
|
||||||
|
nonce: Snowflake;
|
||||||
|
}
|
||||||
|
|
||||||
export class MessageButton extends BaseMessageComponent {
|
export class MessageButton extends BaseMessageComponent {
|
||||||
public constructor(data?: MessageButton | MessageButtonOptions | APIButtonComponent);
|
public constructor(data?: MessageButton | MessageButtonOptions | APIButtonComponent);
|
||||||
public customId: string | null;
|
public customId: string | null;
|
||||||
@ -1927,7 +1932,7 @@ export class MessageButton extends BaseMessageComponent {
|
|||||||
public setStyle(style: MessageButtonStyleResolvable): this;
|
public setStyle(style: MessageButtonStyleResolvable): this;
|
||||||
public setURL(url: string): this;
|
public setURL(url: string): this;
|
||||||
public toJSON(): APIButtonComponent;
|
public toJSON(): APIButtonComponent;
|
||||||
public click(message: Message): Promise<Snowflake>;
|
public click(message: Message): Promise<InteractionResponseBody>;
|
||||||
private static resolveStyle(style: MessageButtonStyleResolvable): MessageButtonStyle;
|
private static resolveStyle(style: MessageButtonStyleResolvable): MessageButtonStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2165,7 +2170,7 @@ export class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
...options: MessageSelectOptionData[] | MessageSelectOptionData[][]
|
...options: MessageSelectOptionData[] | MessageSelectOptionData[][]
|
||||||
): this;
|
): this;
|
||||||
public toJSON(): APISelectMenuComponent;
|
public toJSON(): APISelectMenuComponent;
|
||||||
public select(message: Message, values: string[]): Promise<Snowflake>;
|
public select(message: Message, values: string[]): Promise<InteractionResponseBody>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo
|
// Todo
|
||||||
@ -4307,6 +4312,7 @@ export interface ConstantsEvents {
|
|||||||
API_RESPONSE: 'apiResponse';
|
API_RESPONSE: 'apiResponse';
|
||||||
API_REQUEST: 'apiRequest';
|
API_REQUEST: 'apiRequest';
|
||||||
CLIENT_READY: 'ready';
|
CLIENT_READY: 'ready';
|
||||||
|
APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE: 'applicationCommandAutocompleteResponse';
|
||||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||||
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate';
|
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate';
|
||||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||||
@ -5026,6 +5032,7 @@ export interface ConstantsEvents {
|
|||||||
API_RESPONSE: 'apiResponse';
|
API_RESPONSE: 'apiResponse';
|
||||||
API_REQUEST: 'apiRequest';
|
API_REQUEST: 'apiRequest';
|
||||||
CLIENT_READY: 'ready';
|
CLIENT_READY: 'ready';
|
||||||
|
APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE: 'applicationCommandAutocompleteResponse';
|
||||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||||
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate';
|
APPLICATION_COMMAND_CREATE: 'applicationCommandCreate';
|
||||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||||
@ -6674,6 +6681,7 @@ export interface WelcomeScreenEditData {
|
|||||||
export type WSEventType =
|
export type WSEventType =
|
||||||
| 'READY'
|
| 'READY'
|
||||||
| 'RESUMED'
|
| 'RESUMED'
|
||||||
|
| 'APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE'
|
||||||
| 'APPLICATION_COMMAND_CREATE'
|
| 'APPLICATION_COMMAND_CREATE'
|
||||||
| 'APPLICATION_COMMAND_DELETE'
|
| 'APPLICATION_COMMAND_DELETE'
|
||||||
| 'APPLICATION_COMMAND_UPDATE'
|
| 'APPLICATION_COMMAND_UPDATE'
|
||||||
|
Loading…
Reference in New Issue
Block a user