【问题标题】:Discord.py -- Make the same command with different parameters resulting in different outcomesDiscord.py -- 使用不同的参数执行相同的命令导致不同的结果
【发布时间】:2021-05-02 08:25:01
【问题描述】:

我是 discord.py 的新手。

@bot.command(pass_context=True)

async def AddToDo(ctx, ToDoItem):
    if(ctx.message.author.name not in ToDoList):
        temporaryList.append(ToDoItem)
        ToDoList[ctx.message.author.name] = temporaryList
        await ctx.send(f"Successfully added {ToDoItem} to your To Do List!")

上面的代码工作正常。当用户键入不带参数的“$AddToDo”时,我想添加一条消息来纠正用户。我该怎么做?

注意:我的代码不包含类,但我可以添加一个。不过,我需要一些语法方面的帮助。

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您需要使用命令本地错误处理程序。 例如:

    @AddToDo.error
    async def AddToDo_error(ctx, error):
            error = getattr(error, 'original', error)
            if isinstance(error, commands.MissingRequiredArgument):
               await ctx.send("Missing arguments")
    

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多