on_reaction_add 未运行

时间:2023-05-12
本文介绍了on_reaction_add 未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我是 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 未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:如何让我的 Python discord 机器人在加入时赋予角色? 下一篇:如何检查用户是否在 on_message 中具有特定角色?

相关文章