on_reaction_add not being run(on_reaction_add 未运行)
问题描述
我是 discord.py 的新手,正在尝试制作一个翻译机器人.当用户对某个标志做出反应时,机器人会翻译它,但该事件永远不会被调用,因此我还没有代码来翻译任何消息.我知道它没有被调用,因为程序没有将 'x'
打印到控制台.
I'm new to discord.py and trying to make a translator bot. When the user reacts with a certain flag, the bot translates it, but the event is never getting called hence I have no code to translate any messages yet. I know it's not getting called because the program isn't printing an 'x'
to the console.
@client.event
async def on_reaction_add(reaction, user):
channel = reaction.message.channel
print('x')
await client.send_message(channel, '{} has added {} to the the message {}'.format(user.name, reaction.emoji, reaction.message.content))
await client.process_commands(reaction.message)
推荐答案
事件没有注册/调用的原因并不多.
There isn't much valid reason for why the event isn't registered/called.
其中一个在文档中说明:http://discordpy.readthedocs.io/en/async/api.html#discord.on_reaction_add.尝试立即对机器人在线后发送的消息添加反应.由于在机器人上线之前发送的消息将不会被机器人识别(不在 Client.messages
中).
One of which is stated in the docs: http://discordpy.readthedocs.io/en/async/api.html#discord.on_reaction_add. Try adding a reaction immediately to a message that is sent after the bot is online. Since messages sent before the bot is online will not be recognized by the bot (not in Client.messages
).
如果在 Client.messages
缓存中没有找到消息,那么这个事件不会被调用.
if the message is not found in the
Client.messages
cache, then this event will not be called.
另一个可能的原因是在客户端循环开始之前从未定义过此函数.验证您的缩进.和/或尝试将函数直接放在 client = Bot(...)
下,以检查是否是问题所在.
Another possible reason is that this function was never defined before the client loop commenced. Verify your indentation. And/Or try placing the function directly under client = Bot(...)
, to check if this is the problem.
如果上述方法都不能解决您的问题,请发布一个最小的、完整的、可验证的示例(从上到下的简短可运行代码,表明您的问题).
If neither of the aforementioned solves your problem, please post a minimal, complete, verifiable example (a short runnable code from top to bottom that indicates your problem).
这篇关于on_reaction_add 未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:on_reaction_add 未运行


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