【问题标题】:Discord.py rewrite bot not responding to a normal commandDiscord.py 重写机器人不响应正常命令
【发布时间】:2020-06-03 20:17:30
【问题描述】:

我有一个正常的命令,但我得到这个错误:Command "leave" is not found。这是我的代码: 我之前用过reaction-script,所以我知道不是这样的。

@bot.command
async def leave(ctx):
    user1 = await bot.fetch_user(ctx.message.author.id)
    message = await ctx.send(f"Are you sure that you want to leave {ctx.message.guild}, {ctx.message.author.mention}? React within 30 seconds to verify")
    for emoji in ('✅'):
        await message.add_reaction(emoji)

        try:
            def check(rctn, user):
                return user.id == ctx.author.id and str(rctn) == '✅'

            rctn, user = await bot.wait_for("reaction_add", check=check, timeout=30)

            member = ctx.message.author
            await member.kick()
            user = bot.get_user(ctx.message.author.id)
            link = await ctx.channel.create_invite(unique=True, max_uses=1)
            await user.send(f'You left {ctx.message.guild}! But you can rejoin via {link}')

        except asyncio.TimeoutError:
            await ctx.send(f"**Error:** Not reacted in time")

有人看到错误吗?我似乎找不到它,我认为它应该可以工作。

【问题讨论】:

  • 它是bot.command()(缺少圆括号)。同时提供完整的错误日志。

标签: python-3.x discord discord.py discord.py-rewrite


【解决方案1】:

正如Tin Nguyen 所说,它是 bot.command() 不是 bot.command 就像你在 @bot.event 中所做的那样。

【讨论】:

    【解决方案2】:

    正确的命令装饰器是@bot.command(),文档建议您使用get_user() 而不是fetch_user(),因为后者是一个API 调用。另外,你不能user.send()使用DM,使用user.dm_channel.send()

    @bot.command()
    async def leave(ctx):
        user1 = await bot.get_user(ctx.message.author.id)
        message = await ctx.send(f"Are you sure that you want to leave {ctx.message.guild}, {ctx.message.author.mention}? React within 30 seconds to verify")
        for emoji in ('✅'):
            await message.add_reaction(emoji)
    
            try:
                def check(rctn, user):
                    return user.id == ctx.author.id and str(rctn) == '✅'
    
                rctn, user = await bot.wait_for("reaction_add", check=check, timeout=30)
    
                member = ctx.message.author
                await member.kick()
                user = bot.get_user(ctx.message.author.id)
                link = await ctx.channel.create_invite(unique=True, max_uses=1)
                await user.dm_channel.send(f'You left {ctx.message.guild}! But you can rejoin via {link}')
    
            except asyncio.TimeoutError:
                await ctx.send(f"**Error:** Not reacted in time")
    

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2021-07-07
      • 2021-11-10
      • 2022-01-10
      • 2021-11-29
      • 2020-07-09
      • 2021-11-21
      • 2021-07-22
      • 2021-06-13
      相关资源
      最近更新 更多