机器人在对同一消息的两个反应做出反应时发送消息
Posted
技术标签:
【中文标题】机器人在对同一消息的两个反应做出反应时发送消息【英文标题】:Bot sending messages when reacting to both reactions on the same message 【发布时间】:2021-07-04 00:33:08 【问题描述】:mstatus = True
for mem in members:
memberreact = await mem.user.send("do you wish to approve or decline?\nchoose ⬆️ to approve and ⬇️ to decline!!")
await memberreact.add_reaction("⬆️")
await memberreact.add_reaction("⬇️")
def mcheck1(reaction, user):
return user == mem.user and reaction.message.id == memberreact.id and str(reaction.emoji) == "⬆️"
def mcheck2(reaction, user):
return user == mem.user and reaction.message.id == memberreact.id and str(reaction.emoji) == "⬇️"
async def mreact1(mstatus):
#first logic
if mstatus == True:
reaction, user = await client.wait_for("reaction_add", check=mcheck1)
await mem.user.send("you have approved!!")
mstatus = False
print(mstatus)
async def mreact2(mstatus):
#second logic
if mstatus == True:
reaction, user = await client.wait_for("reaction_add", check=mcheck2)
await mem.user.send("you have decline!!")
mstatus = False
print(mstatus)
await asyncio.gather(mreact1(mstatus), mreact2(mstatus))
这段代码在对⬆️做出反应时给了我第一个逻辑,在同一消息中给我在对⬇️做出反应时给我第二个逻辑..但这没有意义,因为代码中的 mstatus 在最初对⬆️做出反应时变为 False.. 这段代码有问题吗?如果是请告诉我..
【问题讨论】:
【参考方案1】:你打错了,很简单:
async def mreact1(mstatus):
if mstatus == True:
reaction, user = await client.wait_for("reaction_add", check=mcheck1)
await mem.user.send("you have approved!!")
mstatus = False ## SHOULD BE TRUE!!!!!
print(mstatus)
【讨论】:
等等 uhhh.. 与我的这段代码有什么区别..?对不起,我找不到任何.. @arielle 看起来代码是一样的,但有一条评论说你应该把False
改为 True
。以上是关于机器人在对同一消息的两个反应做出反应时发送消息的主要内容,如果未能解决你的问题,请参考以下文章
Discord js v12 如果有人对嵌入做出反应,则发送消息
无法读取未定义的属性“发送”:Discord 机器人创建通道并向其发送消息然后对其做出反应