【发布时间】:2019-11-03 19:51:27
【问题描述】:
有没有办法从命令中捕捉反应。我做了一个删除频道的命令,但我想问用户他们是否确定使用反应。我想阻止其他人对此消息做出反应(只有上下文作者应该做出反应)。
到目前为止,我发现只是使用on_reaction_add() 但这无法检测到发送命令的用户。如果消息作者是对消息做出反应的人,我只想更新命令,其他任何人,忽略它。
更新:我发现wait_for() 完全符合我的要求,但现在的问题是如何检查是否设置了错误的反应? (即如果我按下第二个反应,删除消息)
if is_admin:
msg = await ctx.send('Clear: Are you sure you would like to purge this entire channel?')
emoji1 = u"\u2705"
emoji2 = u"\u274E"
await msg.add_reaction(emoji=emoji1)
await msg.add_reaction(emoji=emoji2)
def check(reaction, user):
return user == ctx.message.author and reaction.emoji == u"\u2705"
try:
reaction, user = await self.client.wait_for('reaction_add', timeout=10.0, check=check)
except asyncio.TimeoutError:
return await msg.delete()
else:
channel = ctx.message.channel
new_channel = await channel.clone(name=channel.name, reason=f'Clear Channel ran by {ctx.message.author.name}')
await new_channel.edit(position=channel.position)
await channel.delete(reason=f'Clear Channel ran by {ctx.message.author.name}')
await new_channel.send('Clear: Channel has now been cleared.', delete_after=7)
else:
await ctx.send(f"Sorry, you do not have access to this command.", delete_after=5)
【问题讨论】:
标签: python-3.x discord.py-rewrite