on_reaction_add not being run

放肆的年华 提交于 2019-12-20 07:38:10

问题


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)

回答1:


There isn't much valid reason for why the event isn't registered/called.

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).

if the message is not found in the Client.messages cache, then this event will not be called.

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).



来源:https://stackoverflow.com/questions/50785641/on-reaction-add-not-being-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!