Search code examples
discord.pynextcord

can't add a nextcord slash command argument ( type error)


When i use nextcord and want toadd an arg too my slash command its says "Non-default argument follows default argument" and when I put None it works . My code :

The error :

async def ping(interaction=Interaction, arg:str):
                                            ^^^^^^^
SyntaxError: non-default argument follows default argument

even when i copy the docs code i have the same prob.


Solution

  • In Python, you cannot have a default argument in front of a required argument in the function parameters. So when you set None as the default value for the arg argument, the error won't be raised.

    Also, it seems like you're setting discord.Interaction class as the default value for the interaction argument. I think you want to make it a type hint, not a default value, so you can just change it a bit.

    Before

    async def ping(interaction=Interaction, arg:str):
    

    After

    async def ping(interaction: Interaction, arg: str):