【问题标题】:discord.py command() got an unexpected keyword argument 'options'discord.py command() got an unexpected keyword argument \'options\'
【发布时间】:2022-12-02 01:42:00
【问题描述】:

So i am trying to make slash ban command in discord.py and i get this error: command() got an unexpected keyword argument 'options'

My code:

@tree.command(name="ban", description="Ban someone", options = [app_commands.choices(name="user", description="select user to ban", option_type=6, required=True)])
async def _ban(ctx, user: discord.Member):
    await user.ban(reason="NO reason")
    await ctx.send(f'Banned {user}! Reason: {reason}')   

【问题讨论】:

    标签: python discord.py


    【解决方案1】:
    @tree.command(name="ban", description="Ban someone")
    async def _ban(ctx, user: discord.Member):
        await user.ban(reason="NO reason")
        await ctx.send(f'Banned {user}! Reason: {reason}')   
    

    If you are only using discord.py, which i assume so, user: discord.Member is enough. options = [app_commands.choices( isn't a thing.

    Read the docs on @discord.app_commands.CommandTree.command

    The real use of app_commands.choices looks like this:

    @tree.command(name='command')
    @app_commands.choices(option=[
      app_commands.Choice(name='option1', value='1'),
      app_commands.Choice(name='option2', value='2'),
    ])
    async def command(interaction: discord.Interaction, option: app_commands.Choice[str]):
        if option.value == '1':
            #chosen option was option1
        elif option.value == '2':
            #chosen option was option2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-19
      • 1970-01-01
      • 2022-01-12
      • 2015-09-23
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多