Skip to content

I have problems to execute my commands after register in applicationCommands #116

@zalazarnatanael

Description

@zalazarnatanael

Hello, i am trying to implement slash commands in my project... But i am having problemas with the implemention.

I created the following function in utils/registry.ts

export async function registerSlashCommands(client: DiscordClient, commands: Collection<string, BaseCommand>) {
  client.configs.forEach(async (guildConfig) => {
    const guild = await client.guilds.fetch(guildConfig.guildId)
    const applicationCommands = guild?.commands || client?.application?.commands
    commands.map(cmd => {
      applicationCommands?.create({ name: cmd.getName().toLowerCase(), description: cmd?.getDescription().toLowerCase() })
    })
  })
}

And, i created the following interactionCreate event

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    if(!interaction.guildId) return;
    const command = await client.commands.get(interaction.commandName)

    if(!command) return;

    try {
      await command.execute(interaction);
    } catch(e) {
      if(e) console.log(e)

      await interaction.reply({
        content: 'An error ocurred while executing that command.',
        ephemeral: true
      })
    }
  })

My problem is the function "execute" not exist, and i don't know how to fix it

await command.execute(interaction);

What can i do to solve it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions