【问题标题】:Discord.py How to do an action depending on the user reactionDiscord.py 如何根据用户反应执行操作
【发布时间】:2020-02-25 03:18:10
【问题描述】:
如何检查用户的反应?我正在使用该代码:
@client.command()
async def react(ctx):
message = await ctx.send("Test")
await question.add_reaction("<????>")
await question.add_reaction("<????>")
如果用户对消息做出反应 ????如果用户对消息做出反应 ?????提前谢谢你
【问题讨论】:
标签:
discord.py
discord.py-rewrite
【解决方案1】:
在documentation 中,您可以找到等待事件发生的client.wait_for()。文档中的示例应该可以帮助您:
@client.event
async def on_message(message):
if message.content.startswith('$thumb'):
channel = message.channel
await channel.send('Send me that ? reaction, mate')
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '?'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('?')
else:
await channel.send('?')