Initial commit
This commit is contained in:
31
events/handle-commands.ts
Normal file
31
events/handle-commands.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {Interaction} from 'discord.js';
|
||||
|
||||
import {isExtendedClient} from '../classes/extendedclient';
|
||||
import {logger} from '../logger';
|
||||
|
||||
export async function handleCommands(interaction: Interaction): Promise<void>{
|
||||
if(!interaction.isChatInputCommand()) return;
|
||||
if(interaction.commandName === null)
|
||||
throw logger.error('interaction.commandName not exist');
|
||||
if(!isExtendedClient(interaction.client))
|
||||
throw logger.error(`Type Error in function "handleCommands"`);
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
if(!command)
|
||||
throw logger.error(`No command matching ${interaction.commandName} was found.`);
|
||||
|
||||
try{
|
||||
if('execute' in command)
|
||||
await command.execute(interaction);
|
||||
else{
|
||||
logger.error(`The command (${interaction.commandName}) is missing a require "execute" function`);
|
||||
return;
|
||||
}
|
||||
}catch(err: unknown){
|
||||
if(interaction.replied || interaction.deferred)
|
||||
await interaction.followUp({content: 'There was an error while executing this command!', ephemeral: true});
|
||||
else
|
||||
await interaction.reply({content: 'There was an error while executing this command!', ephemeral: true});
|
||||
throw logger.error(`While handling "${interaction.commandName}, ${err}"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user