为了账号安全,请及时绑定邮箱和手机立即绑定

在discord.py wait_for 上使用 check() 时出现类型错误

在discord.py wait_for 上使用 check() 时出现类型错误

慕勒3428872 2023-12-29 10:05:30
我有一个机器人将打开一个使用 wait_for(reaction_add) 功能的关闭民意调查。问题是,当我检查作者是否做出反应时,我收到了 TypeError。这是命令:@bot.command()async def closepoll(ctx):    if not ctx.author.guild_permissions.mute_members:        await ctx.send("You cannot use this")    else:        await ctx.send("React to the poll I must close")        def check(m):            return m.author == ctx.author        try:            reaction, user = await bot.wait_for('reaction_add', timeout=120.0, check=check)        except asyncio.TimeoutError:            await ctx.send('Did not receive any reaction')        else:            message = reaction.message            if message.content.startswith("Poll:") and str(user) == str(ctx.author):                await message.edit(content="This poll is now closed.")            else:                await ctx.send("That is not a poll")但我收到错误:Traceback (most recent call last):  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped    ret = await coro(*args, **kwargs)  File "hypixel.py", line 138, in closepoll    except asyncio.TimeoutError:  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py", line 483, in wait_for    return fut.result()  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 339, in dispatch    result = condition(*args)TypeError: check() takes 1 positional argument but 2 were givenThe above exception was the direct cause of the following exception:
查看完整描述

1 回答

?
喵喵时光机

TA贡献1846条经验 获得超7个赞

应该采用的参数数量check取决于您正在等待的事件。反应_add事件有两个参数,但你的函数只有一个。

尝试用两个参数定义一个检查函数。例如,文档给出了示例:

def check(reaction, user):
    return user == message.author and str(reaction.emoji) == '👍'


查看完整回答
反对 回复 2023-12-29
  • 1 回答
  • 0 关注
  • 49 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信