当用户对 2 个反应做出反应时,机器人不会读取第二个反应.. discord.py
Posted
技术标签:
【中文标题】当用户对 2 个反应做出反应时,机器人不会读取第二个反应.. discord.py【英文标题】:Bot doesn't read the second reaction when user reacts to 2 reaction.. discord.py 【发布时间】:2021-06-28 02:51:05 【问题描述】:我有一个代码,机器人需要读取用户对消息的两种反应,但使用此代码,机器人不会打印“第二次检查”,这意味着机器人不阅读第二次反应和在第一个实现后停止
reacttn = True
def check(reaction, user):
return user == members.users[members.leader].user and reaction.message.id == ttreact.id
while reacttn == True:
reaction, user = await client.wait_for("reaction_add", check=check)
if len(members.users) == 2:
if str(reaction.emoji) == "1️⃣":
print("first check")
if str(reaction.emoji) == "2️⃣":
print("second check")
await asyncio.sleep(5)
reacttn = False
【问题讨论】:
【参考方案1】:你可以这样做:
from collections.abc import Sequence
def sequence(seq):
if seq is None:
return ()
if isinstance(seq, Sequence) and not isninstance(seq, str):
return seq
else:
return(seq,)
def reaction_check:(message=None, emoji=None, author=None, ignore_bot=True):
message = sequence(message)
message = tuple(m.id for m in message)
emoji = sequence(emoji)
author = sequence(author)
def check(reaction, user):
if ignore_bot and user.bot:
return False
if message and reaction.message.id not in message:
return False
if emoji and reaction.emoji not in emoji:
return False
if author and user not in author:
return False
return True
return check
在命令中:
msg = await ctx.send("react to this message!")
await msg.add_reaction("1️⃣")
await msg.add_reaction("2️⃣")
check = reaction_check(message=msg, author=member, emoji=("1️⃣","2️⃣"))
reaction, user = await client.wait_for("reaction_add", check=check)
if reaction.emoji == "1️⃣":
#first logic
if reaction.emoji == "2️⃣":
#second logic
【讨论】:
我做了和以前一样但相同的结果..我知道为什么.. 这很奇怪....尝试启用intents.reactions
是的..我发现了问题..问题就像单独检查 wait_for
并单独检查单独的反应,因为 wait_for
只等到它成真..!以上是关于当用户对 2 个反应做出反应时,机器人不会读取第二个反应.. discord.py的主要内容,如果未能解决你的问题,请参考以下文章