問題描述
我正在使用 async def on_raw_reaction_remove(payload)
來跟蹤用戶何時刪除反應.如何獲取觸發事件的用戶?在我的代碼中,我讓我的機器人通過在某些情況下刪除反應來觸發此事件 - 但是當這種情況發生時 user = await client.fetch_user(user_id)
總是等于對刪除的反應做出反應的用戶并且不是刪除它的機器人(當機器人刪除某人的反應時,我需要讓機器人成為用戶,所以我可以說 if user == bot: return我也試過了
I am using async def on_raw_reaction_remove(payload)
to track when a user removes a reaction..
How do I get the user who triggered the event? In my code i have my bot trigger this event by removing reactions in certain scenarios - but when this happens user = await client.fetch_user(user_id)
always equals to the user who had reacted with the removed reaction and not the bot that removed it (i need to get the bot as user when the bot removes someone's reaction, so i can say if user == bot: return
I also tried
message = await channel.fetch_message(payload.message_id)
guild = message.guild
member = await guild.fetch_member(payload.user_id)
但它是相同的.. 成員始終指向已刪除反應的所有者,而不是刪除反應的機器人...使用 on_raw_reaction_remove 時,我怎樣才能得到消除反應的人?
but it's the same.. the member is always pointing to the owner of the reaction that was removed, not the bot that's removing the reaction... How can i get the one who is removing the reaction when using on_raw_reaction_remove?
(如果相關 - 我在 discord 的開發者門戶中啟用了意圖并更新了我的代碼
(if it's relevant - i enabled intents in discord's developer portal and updated my code with
intents = discord.Intents.all()
client = discord.Client(intents=intents)
感謝您的幫助,我已經在這方面浪費了很多時間:皺眉:(不和諧 api 的新手)
Thanks for your help, i wasted so much time on this already :frowning: (new to the discord api)
推薦答案
答案是——discord python API 中沒有任何東西可以告訴你是誰刪除了反應.
The answer is - there is nothing in the discord python API that can tell you who removed the reaction.
對于我的情況,我通過一種解決方法解決了這個問題 - 我只需要跟蹤我的機器人是否刪除了一個帶有變量的反應 - 我正在使用一個全局變量來跟蹤我的機器人何時刪除了一個反應,然后稍后再檢查是否變量是 True
或 False
并做出相應的響應并重新設置變量.
For my case, I solved it with a workaround - I just had to track if my bot removed a reaction with a variable - I am using a global variable to track when my bot removes a reaction and then just check later if the variable is True
or False
and respond accordingly and reset the variable back.
謝謝
這篇關于獲取觸發 on_raw_reaction_remove(payload) 的用戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!