对消息的反应

时间:2020-01-08 12:37:00

标签: python-3.x discord.py

我的代码

@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'

如何解决此错误?

1 个答案:

答案 0 :(得分:2)

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

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

您可以查看其常见问题解答以获取更多帮助:"How do I add a reaction to a message?"