on_reaction_add未运行 [英] on_reaction_add not being run

查看:72
本文介绍了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未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆