有没有办法捕捉命令的反应。我做了一个命令,删除一个频道,但我想问用户,如果他们确定使用反应。我想阻止其他人对此消息作出反应(只有上下文作者应该作出反应)。在
到目前为止,我发现的只是使用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)
下面是我用来为
wait_for
生成check
函数的函数:我们可以传递要等待的消息、用户和表情符号,它会自动忽略其他所有内容。在
^{pr2}$相关问题 更多 >
编程相关推荐