Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zalazarnatanael opened this issue Jan 15, 2022 · 5 comments

Comments

@zalazarnatanael
Copy link

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?

@loveisglitchy
Copy link

I think you need to use command.run instead of command.execute. Try this and report back.

@zalazarnatanael
Copy link
Author

I dont know how to use command.run because it needs message arguments and in the event interactionCreate i don't how to obtain it.

@loveisglitchy
Copy link

loveisglitchy commented Jan 15, 2022

Change that line that's faulting out... .execute > .run

Also, an interaction doesn't take in the message.

@zalazarnatanael
Copy link
Author

The .run request me the following arguments
Captura de Pantalla 2022-01-15 a la(s) 20 43 00

@zalazarnatanael
Copy link
Author

somebody can help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants