【发布时间】:2021-03-04 11:18:40
【问题描述】:
如果你 DM 机器人,它会发送一条消息并添加一些反应,然后等待用户添加反应,然后再做某事。
我的问题是,如果用户再次 DM 机器人,它会发送另一条消息,如果用户对任何机器人消息做出反应,机器人会根据您从机器人收到的消息数量执行两次或更多操作。
如果当前有一条带有反应的消息,是否有办法让机器人不发送另一条消息,并等待用户先做出反应,然后机器人才能再次发送另一条带有反应的消息?谢谢。
async def on_message(self, message):
if message.author.bot:
return
if isinstance(message.channel, discord.DMChannel):
dm = await message.channel.send('test')
await dm.add_reaction("1️⃣")
def check(reaction, user):
return user == message.author and str(reaction.emoji) in ["1️⃣"]
while True:
try:
reaction, user = await self.client.wait_for("reaction_add", timeout=15, check=check)
if str(reaction.emoji) == "1️⃣":
# do something here
except asyncio.TimeoutError:
await dm.delete()
break
【问题讨论】:
-
while 循环的目的是什么?
标签: python discord.py