【问题标题】:Gathering reactions from a private DM but ignoring bot reactions收集私人 DM 的反应但忽略机器人反应
【发布时间】:2019-06-01 02:13:15
【问题描述】:

我正在为我的机器人发出命令,它会向您发送以下消息:

两个反应(勾号和交叉)成为机器人的预反应,以向用户展示该做什么。我不希望我的机器人等待一段时间并检查用户的反应,此时我的机器人会计算自己的反应,所以计数是错误的。

我该怎么做呢,我尝试过的一切都失败了,我不能再按 Ctrl+Z 到我有一个模糊的工作代码的地步。

谢谢。

编辑:经过多次尝试,我实际上在半小时前解决了我的问题,这是我使用的:

res1 = await client.wait_for_reaction(emoji="✅", message=message_1, timeout=10)
res2 = await client.wait_for_reaction(emoji="❌", message=message_1, timeout=10)
if not res1.user == None or not res2.user == None:
   if not res1.user.id == client.user or res2.user.id == client.user:

【问题讨论】:

  • 目前我的机器人计算自己的反应,所以计数是错误的。你能告诉我们你的代码吗?

标签: python-3.x discord.py


【解决方案1】:

执行此操作的最佳方法是向您添加一个check wait_for_reaction,它只检查反应用户与client.user。这样做的好处是还可以在您想要接受一个反应的情况下工作,并且如果您不小心看到机器人反应,就无法执行另一个循环

def not_bot_reaction(reaction, user):
    return user != client.user

...

res1 = await client.wait_for_reaction(emoji="✅", message=message_1, timeout=10, check=not_bot_reaction)
res2 = await client.wait_for_reaction(emoji="❌", message=message_1, timeout=10, check=not_bot_reaction)

if res1 or res2:  # If the wait_for times out, it will return None instead of the namedtuple
    ...

【讨论】:

    猜你喜欢
    • 2021-11-14
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2021-10-10
    • 2022-10-30
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多