問題描述
我正在使用 python 制作一個 Discord Bot,我希望一條消息只有某些反應,并且在添加反應時,我希望代碼刪除每個不需要的反應.我真的希望它驗證是否沒有其他反應要刪除,而不僅僅是剛剛添加的那個.
I am making a Discord Bot using python and I want a message to have only certain reactions and on adding a reaction I want the code to delete every unwanted one. I really want it to verify if there is no other reactions to remove, not only the one that has just been added.
如標題所述,我的問題是我不知道為什么,但 clear_reaction()
清除了所有反應.
My problem, as said in the title, is that I don't know why but clear_reaction()
clears all reactions.
這是我的代碼:
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)
謝謝.
推薦答案
這將刪除所有反應而不是機器人它.
This is going to remove all reactions instead of the bot it.
你可以做這樣的事情.if 語句只是為了檢查它是否不是機器人本身,它會刪除所有不是機器人做出的反應.
You can do something like this. The if statement is just to check if it is not the bot itself, it will remove all reactions not made by the bot.
@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)
這篇關于Python Discord Bot - python clear_reaction() 清除所有反應而不是特定反應的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!