Get the user who triggered the on_raw_reaction_remove(payload)(获取触发 on_raw_reaction_remove(payload) 的用户)
问题描述
我正在使用 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) 的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取触发 on_raw_reaction_remove(payload) 的用户


基础教程推荐
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01