mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
feat!: Extracted handling of interactions into separate files
This commit is contained in:
1 parent
8e9cb308e9
commit
780e20d419
7 files changed
+166
-153
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { ChatInputCommandInteraction } from 'discord.js';
|
||||
import { Command, ExtendedClient } from '../types/clientTypes';
|
||||
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
|
||||
import loggerModule from '../services/logger';
|
||||
|
||||
const logger = loggerModule.child({
|
||||
source: 'interactionCommandHandler.ts',
|
||||
module: 'handler',
|
||||
name: 'interactionCommandHandler'
|
||||
});
|
||||
|
||||
export const handleCommand = async (
|
||||
interaction: ChatInputCommandInteraction,
|
||||
client: ExtendedClient,
|
||||
executionId: string
|
||||
) => {
|
||||
await interaction.deferReply();
|
||||
logger.debug('Interaction deferred.');
|
||||
|
||||
const command = client.commands?.get(interaction.commandName) as Command;
|
||||
if (!command) {
|
||||
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
logger.debug('Executing command interaction.');
|
||||
await command.execute({ interaction, client, executionId });
|
||||
};
|
||||
Reference in new issue
Block a user