node-event-bot/server/events/interactionCreate.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-04-12 22:39:47 +02:00
import { CommandInteraction, CommandInteractionOptionResolver } from "discord.js"
import { ExtendedInteraction } from "../types/commandTypes"
import { Event } from '../structures/event'
import { client } from "../.."
/**
export default new Event('interactionCreate', async (interaction) => {
console.log(`Interaction has been created, ${JSON.stringify(interaction)}`)
if (interaction.isCommand()) {
await interaction.deferReply()
const command = client.commands.get(interaction.commandName)
if (!command)
return interaction.followUp('You have used a non existant command')
command.run({
args: interaction.options as CommandInteractionOptionResolver,
client: client,
interaction: interaction as ExtendedInteraction
})
}
})
*/
export const name = 'interactionCreate'
export async function execute(interaction: ExtendedInteraction) {
//console.dir(interaction, { depth: null })
if (interaction.isCommand()) {
console.log(`Interaction is a command.`)
await interaction.deferReply()
const command = client.commands.get(interaction.commandName)
if (!command)
return interaction.followUp('Invalid command')
command.run({
args: interaction.options as CommandInteractionOptionResolver,
client,
interaction
})
}
}