【问题标题】:'Bot' object has no attribute 'wait_for_reaction''Bot' 对象没有属性 'wait_for_reaction'
【发布时间】:2022-01-19 06:02:55
【问题描述】:

错误:'Bot' Has No Attribute Called 'wait_for_reaction',这是代码:

if int(pp) >= 19:
        gh = await message.send('''
Your Number Is Higher Or Is 20... Click ⬆ To Continue''')
        await gh.add_reaction("⬆")
        await bot.wait_for_reaction('⬆', gh)

顺便说一句bot = command.Bot()

【问题讨论】:

  • 请包括您对bot 的定义、它所扩展的类以及您正在使用的库(如果可能,请提供版本)

标签: python discord discord.py message


【解决方案1】:

你需要使用wait_for:

await bot.wait_for("raw_reaction_add", timeout=180, check=lambda payload: payload.member == ctx.author and str(payload.emoji) == "⬆")

【讨论】:

    【解决方案2】:

    bot.wait_for_reaction 不再是 discord.py 的一部分并且已被弃用。相反,您应该使用bot.wait_for(),让机器人“等待”一个反应,并检查反应的作者是否是消息的作者。请查看下面修改后的代码中的进一步说明:

    if int(pp) >= 19:
            gh = await message.send('''
    Your Number Is Higher Or Is 20... Click ⬆ To Continue''')
            await gh.add_reaction("⬆")
    
            # New code starts here #
    
            # Define your check
            # Checks if the reaction author is the author of the message
            # and if the reaction emoji is '⬆'
            def check(reaction, user):
                    return user == message.author and str(reaction.emoji) == '⬆'
    
            try:
                    reaction, user = await bot.wait_for("reaction_add",check=check,timeout=10)
            except asyncio.TimeoutError: # That way the bot doesn't wait forever for a reaction
                    await message.send("Ran out of time, interaction ended")
                    return
            if reaction: 
                    # 'if statement' is regarded if the given reaction is valid (and not None)
                    # Continue with the rest of your code
    

    这样的问题

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 2020-03-21
      • 2021-09-26
      • 1970-01-01
      • 2022-12-09
      • 2020-10-22
      • 2020-11-11
      • 2018-06-15
      相关资源
      最近更新 更多