首页 > 解决方案 > 对消息的反应

问题描述

我的代码

@bot.event
async def on_message(message):
  emoji = ''
  message = message.id
  await bot.add_reaction(message, emoji)

控制台错误

Ignoring exception in on_message
Traceback (most recent call last):
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 31, in on_message
AttributeError: 'Bot' object has no attribute 'add_reaction'

如何修复此错误?

标签: python-3.xdiscord.py

解决方案


正如 python 解释器有用地指出的那样,您的Bot对象没有 function add_reaction()。相反,它可用于Message对象:

@bot.event
async def on_message(message):
  emoji = ''
  await message.add_reaction(emoji)

您可以查看他们的常见问题解答以获得更多帮助:“如何添加对消息的反应?”


推荐阅读