pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Error in slash commands parameters when naming them UpperCamelCase or camelCase

Open Mootbing opened this issue 5 years ago • 14 comments

Summary

When you put in a capital letter in one of the options for a .slash_command function, it doesn't run

Reproduction Steps

take the following:

async def hello(
    ctx,
    gamecode: Option(str, "Code to the game")
):

it runs fine

if you do this:

async def hello(
    ctx,
    GameCode: Option(str, "Code to the game")
):

it will not run. Here is the error

c:/Users/kingo/Documents/GitHub/MurderMoostery/SRC/Test.py
Ignoring exception in on_connect
Traceback (most recent call last):
  File "C:\Users\kingo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", 
line 351, in _run_event
    await coro(*args, **kwargs)  
  File "C:\Users\kingo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\bot.py", line 370, in on_connect
    await self.register_commands()
  File "C:\Users\kingo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\bot.py", line 196, in register_commands      
    cmds = await self.http.bulk_upsert_guild_commands(self.user.id, guild_id,
  File "C:\Users\kingo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\http.py", line 335, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 0.options.0.name: Command name is invalid```


### Minimal Reproducible Code

```python
import discord
from discord.app import Option

bot = discord.Bot()

@bot.slash_command(description="Join game")
async def hello(
    ctx,
    Gamecode: Option(str, "Code to the game"),
):
    await ctx.respond(f"Code: {GameCode}")

bot.run("token")

Expected Results

for it to run correctly with the rightly formatted capitalizations

Actual Results

it didn't run at all

Intents

none

System Information

I installed from GitHub with slashcommands branch, so it doesn't work and gives me an error when I run that. But I am using python 3.9.7 and using the latest version of the slash commands branch (just got today)

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

No response

Mootbing avatar Sep 17 '21 01:09 Mootbing

This is a discord limitation, you can't have capital letters in the option names :/

CodeWithSwastik avatar Sep 17 '21 02:09 CodeWithSwastik

oh I see. Can you keep this issue open and/or add it to the FAQ? since I saw a lot of people having the same issue in the discord chat but they didn't figure it out.

Mootbing avatar Sep 17 '21 16:09 Mootbing

@CodeWithSwastik then how about the option names be converted to lowercase before being sent to discord?

ImNimboss avatar Sep 30 '21 12:09 ImNimboss

@CodeWithSwastik then how about the option names be converted to lowercase before being sent to discord?

That would cause even more confusion among users.

izxxr avatar Sep 30 '21 13:09 izxxr

And we don't know when Discord changes it so we don't handle stuff that are subject to change anytime.

izxxr avatar Sep 30 '21 13:09 izxxr

@nerdguyahmad That would cause even more confusion among users.

I disagree. Prevention of error and informing users who are confused by the lowercase that its a discord limitation seems like the better option. I think its more confusing to get an error that says the command name is invalid when its the option thats the problem.

LilJess13 avatar Sep 30 '21 15:09 LilJess13

I think we should convert it to lowercase and note in the documentation that it gets changed.

Dorukyum avatar Sep 30 '21 15:09 Dorukyum

But @LilJess13, My second point was that it is subject to change anytime. Just like embed limitations that change often. e.g description changed from 2048 char limit to 4096.

izxxr avatar Sep 30 '21 16:09 izxxr

Besides, That error shows that it's caused by Discord and not library.

izxxr avatar Sep 30 '21 16:09 izxxr

Interesting point, but how about this: If the error occurs then its caught by the library itself and sent into the logging module to get logged. If the error doesn't occur, then everything's fine

ImNimboss avatar Sep 30 '21 16:09 ImNimboss

Interesting point, but how about this: If the error occurs then its caught by the library itself and sent into the logging module to get logged. If the error doesn't occur, then everything's fine

There're number of reasons HTTPException can occur. Same for Invalid command name error. And making an entirely different exception class for this is too much. Hence, I think it would be better if we leave it as is.

izxxr avatar Sep 30 '21 17:09 izxxr

@nerdguyahmad That would cause even more confusion among users.

I disagree. Prevention of error and informing users who are confused by the lowercase that its a discord limitation seems like the better option.

I think its more confusing to get an error that says the command name is invalid when its the option thats the problem.

I agree. This is why I want the issue opened even though it's been solved. (I'm assuming) Many people (including myself) have been tripped up by this. So this will definitely help, or saying something when ran that says "no caps in command name!"

Mootbing avatar Sep 30 '21 17:09 Mootbing

I'm thinking that there should be a seperate section in FAQ's, "Interactions & Application Commands" with frequently asked questions, like this one.

izxxr avatar Sep 30 '21 17:09 izxxr

Closing as this is a Discord limitation and it's been almost 7 months.

Dorukyum avatar Apr 09 '22 18:04 Dorukyum