nyxx-discord / nyxx_commands

A framework for easily creating slash commands and text commands for Discord using the nyxx library.
Apache License 2.0
13 stars 5 forks source link

Allow guild & global slash commands with same name #143

Open priyanuj-gogoi opened 1 year ago

priyanuj-gogoi commented 1 year ago

Describe the bug

Throws CommandRegistrationError when trying to create a guild & a global slash command having same name.

To Reproduce

  1. Create a guild & a global slash command with same name.

    final globalSlash = ChatCommand(
     'slash', // Same name as "guildSlash"
     'placeholder',
     id(...)
    );
    
    final guildSlash = ChatCommand(
     'slash', // Same name as "globalSlash"
     'placeholder',
     singleChecks: [GuildCheck.id(...)],
     id(...)
    );
  2. Add them in your client's CommandsPlugin().
    final commands = CommandsPlugin(...)
     ..addCommand(globalSlash)
     ..addCommand(guildSlash);
  3. Run the bot & you'll get this error.
    Command with name "slash" already exists

Expected behavior

Perform the below curl command & then, check your bot slash commands. You'll see 2 slash commands having same name slash. Here, one is guild & the other one is global. This is what we want i.e to create guild & global slash commands with same name in nyxx_commands.

curl 'https://discord.com/api/v10/applications/BOT_ID/{guilds/GUILD_ID/,}commands' \
  -H 'Content-Type: application/json' -H 'Authorization: Bot TOKEN' \
  -d '{"name": "slash", "description": "placeholder"}'

[!IMPORTANT] When performing the above request, do replace BOT_ID, GUILD_ID & TOKEN with actual values.

Desktop:

abitofevrything commented 11 months ago

Just had a look at this, and it's more complicated that it might first seem.

These are the two big issues:

I think the best solution would be to disallow this. It is supported by Discord, but I don't think it's great for UX and it's ambiguous how nyxx_commands should handle it.