mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
feat!: New event handling
This commit is contained in:
1 parent
d8951284cb
commit
12d9234271
18 files changed
+324
-152
No files matched your search
@@ -0,0 +1,75 @@
|
||||
const path = require('node:path');
|
||||
const logger = require(path.resolve('./src/services/logger.js'));
|
||||
const { Events, EmbedBuilder } = require('discord.js');
|
||||
const { embedColors, embedIcons, botInfo } = require(path.resolve('./config.json'));
|
||||
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
isDebug: false,
|
||||
execute: async (interaction, { client }) => {
|
||||
if (!interaction.isCommand()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const inputTime = new Date();
|
||||
await interaction.deferReply();
|
||||
await command.run({ interaction, client });
|
||||
const outputTime = new Date();
|
||||
const executionTime = outputTime - inputTime;
|
||||
|
||||
if (executionTime > 20000) {
|
||||
// don't send warning message for commands with collector timeouts, as collector timeout happens after 60 seconds
|
||||
if (
|
||||
(interaction.commandName === 'filters' || interaction.commandName === 'nowplaying') &&
|
||||
executionTime > 55000
|
||||
) {
|
||||
logger.info(
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' executed in ${executionTime} ms.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' took ${executionTime} ms to execute.`
|
||||
);
|
||||
|
||||
return await interaction.followUp({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedIcons.warning} Warning**\nThis command took ${
|
||||
executionTime / 1000
|
||||
} seconds to execute.\n\n_If you experienced problems with the command, please try again._`
|
||||
)
|
||||
.setColor(embedColors.colorWarning)
|
||||
]
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' executed in ${executionTime} ms.`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
error,
|
||||
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' failed to execute.`
|
||||
);
|
||||
|
||||
await interaction.followUp({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedIcons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._`
|
||||
)
|
||||
.setColor(embedColors.colorError)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user