【发布时间】:2021-04-30 07:52:06
【问题描述】:
我正在尝试对我的代码进行确认投票,以便我的机器人在没有确认我想要这样做的情况下不会清除消息。
我正在尝试通过反应投票来做到这一点,当我输入命令时,它会发送一条消息以及 tick 和 cross 反应。如果我用 tick 表情符号 (<:nonatick:803586318369292289>) 做出反应,它会继续清除消息,而如果我用 cross 表情符号 (<:RedTick:801684348502933525>) 做出反应,它会发送另一条消息,然后什么都不做。
我已经得到了它发送Are you sure you want to delete 1 messages? 的部分以及机器人的反应。但是,如果我对任何一个表情符号做出反应,它都不会进一步响应。
@client.command(pass_context=True)
@commands.has_permissions(manage_messages=True)
async def clear(ctx, number):
number = int(number)
moreoma = ctx.author.id
message = await ctx.send("Are you sure you want to delete " + str(number) + " messages?")
# Adds reaction to above message
for emoji in ('<:nonatick:803586318369292289>', '<:RedTick:801684348502933525>'):
await message.add_reaction(emoji)
def check(reaction, user):
return user.id == moreoma and str(reaction.emoji) in ['<:nonatick:803586318369292289>',
'<:RedTick:801684348502933525>']
reaction, user = await client.wait_for('reaction_add', timeout=5, check=check)
if reaction.emoji == '<:nonatick:803586318369292289>':
await ctx.channel.purge(limit=number + 2, check=lambda msg: not msg.pinned)
elif reaction.emoji == '<:RedTick:801684348502933525>':
await ctx.send("aight looks like we are not clearing messages as of now. ")
在我的代码中启用了意图:
intents = discord.Intents(messages=True, guilds=True)
intents.reactions = True
intents.members = True
这就是我使用该命令时发生的情况。
它检查我是否有反应的方式有问题吗?
提前感谢您的帮助!
【问题讨论】:
标签: python discord discord.py