我正在使用python创建Discord Bot,并且我希望消息仅具有某些反应,并且在添加反应时,我希望代码删除所有不需要的代码。我真的希望它验证是否没有其他要删除的反应,不仅仅是刚刚添加的反应。
如标题中所述,我的问题是我不知道为什么,但是clear_reaction()
清除了所有反应。
这是我的代码:
inter_totale = ["✅", "❌"]
@bot.event
async def on_raw_reaction_add(payload):
emoji, user, member, channel = payload.emoji, await bot.fetch_user(user_id=payload.user_id), payload.member, bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
if payload.message_id == specific_message:
if inter_totale.count(emoji.name):
pass # NOT DONE YET
else: # deletes unwanted reactions
for r in msg.reactions:
if not inter_totale.count(r.emoji):
await msg.clear_reaction(r)
谢谢。
答案 0 :(得分:1)
这将删除所有反应,而不是使它成为机器人。
您可以执行以下操作。 if语句仅用于检查它是否不是机器人本身,它将删除该机器人没有做出的所有反应。
@bot.event
async def on_raw_reaction_add(payload):
channel = await bot.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)
inter_totale = ["✅", "❌"]
if user.id != bot.user.id and payload.emoji.name not in inter_total:
await reaction.remove(payload.member)