【问题标题】:Use multiple cooldowns discord.py使用多个冷却 discord.py
【发布时间】:2022-01-18 00:56:56
【问题描述】:

我一直在尝试使用多个冷却时间(用于无效命令和命令冷却时间),但对于两个 on_command_error 事件,我都得到了 Redefinition of usage

这是我目前拥有的:

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        myEmbed1000 = discord.Embed(description=f":x: {random.choice(silly_e)} {ctx.author.name}, that is not a vaild command!", color=0xDD2E44)

        await ctx.reply(embed=myEmbed1000)

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        cooldownem = discord.Embed(description=f"{random.choice(silly_e)} **{ctx.author.name}**, please wait after {round(error.retry_after)} second(s)!", color=0xfae93a)

        await ctx.reply(embed=cooldownem)

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您不能使用两个on_command_error 事件。如果您想捕获多个错误(冷却时间、无效命令等)。您应该只使用一个事件并创建多个if/elif 语句:

    @client.event
    async def on_command_error(ctx, error):
        if isinstance(error, commands.CommandNotFound):
            myEmbed1000 = discord.Embed(description=f":x: {random.choice(silly_e)} {ctx.author.name}, that is not a vaild command!", color=0xDD2E44)
            await ctx.reply(embed=myEmbed1000)
    
        elif isinstance(error, commands.CommandOnCooldown):
            cooldownem = discord.Embed(description=f"{random.choice(silly_e)} **{ctx.author.name}**, please wait after {round(error.retry_after)} second(s)!", color=0xfae93a)
            await ctx.reply(embed=cooldownem)
    

    【讨论】:

    • 谢谢!它有效
    猜你喜欢
    • 2021-05-13
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 2020-11-25
    • 2021-05-02
    • 2021-04-21
    相关资源
    最近更新 更多