Compare commits
2 Commits
f70912e4fd
...
d3d9a305d0
Author | SHA1 | Date | |
---|---|---|---|
d3d9a305d0 | |||
905ee9d8a9 |
@ -1,6 +1,6 @@
|
|||||||
import { Events } from 'discord.js';
|
import { Events } from 'discord.js';
|
||||||
|
|
||||||
const chatInputCommand = async (interaction, command) => {
|
const executeCommand = async (interaction, command) => {
|
||||||
// Try executing command
|
// Try executing command
|
||||||
try {
|
try {
|
||||||
console.info(`[INFO] Command ${interaction.commandName} was executed.`);
|
console.info(`[INFO] Command ${interaction.commandName} was executed.`);
|
||||||
@ -21,9 +21,9 @@ const chatInputCommand = async (interaction, command) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const genericExecute = async (interaction, command, name, description) => {
|
const genericExecute = async (interaction, command, name, description, cmdName) => {
|
||||||
try {
|
try {
|
||||||
console.info(`[INFO] Command ${interaction.commandName} ${description ?? `used "${name}"`}.`);
|
console.info(`[INFO] Command ${(cmdName ?? interaction.commandName) ?? 'anonymous'} ${description ?? `used "${name}"`}.`);
|
||||||
await command[name](interaction);
|
await command[name](interaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -34,9 +34,9 @@ export const name = Events.InteractionCreate;
|
|||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
let command = interaction.client.commands.get(interaction.commandName);
|
let command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
// Execute slash commands
|
// Execute slash- and context-menu-commands
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand() || interaction.isMessageContextMenuCommand()) {
|
||||||
await chatInputCommand(interaction, command);
|
await executeCommand(interaction, command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Autocomplete input
|
// Autocomplete input
|
||||||
@ -44,12 +44,12 @@ export async function execute(interaction) {
|
|||||||
await genericExecute(interaction, command, 'autocomplete');
|
await genericExecute(interaction, command, 'autocomplete');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Modeal submit event
|
// Modal submit event
|
||||||
if (interaction.isModalSubmit()) {
|
if (interaction.isModalSubmit()) {
|
||||||
const name = interaction.customId.split('-')[0];
|
const name = interaction.customId.split('-')[0];
|
||||||
command = interaction.client.commands.get(name);
|
command = interaction.client.commands.get(name);
|
||||||
|
|
||||||
await genericExecute(interaction, command, 'modalSubmit', 'submitted a modal');
|
await genericExecute(interaction, command, 'modalSubmit', 'submitted a modal', name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user