python-3.x - 对消息的反应
问题描述
我的代码
@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 解释器有用地指出的那样,您的Bot
对象没有 function add_reaction()
。相反,它可用于Message
对象:
@bot.event
async def on_message(message):
emoji = ''
await message.add_reaction(emoji)
您可以查看他们的常见问题解答以获得更多帮助:“如何添加对消息的反应?”
推荐阅读
- pycharm - 使用 GitHub CLI 创建 repo 时是否可以更改、克隆目录?
- reactjs - Reactjs-Popup:无法读取未定义的属性(读取“forwardRef”)
- javascript - JSDOM 环境的 Jest 测试运行器的运行时
- calendar - Apple 日历和 Google 日历 URL 不兼容 URL 太长
- angular - 这是避免参数使用 ENUM 的一种懒惰方式吗?
- amazon-web-services - 从 SQS 队列启动 AWS Batch
- react-native - 错误:无法从 *:\*\*\node_modules\react-native-reanimated\src\Animated.js 解析模块 ./reanimated1:
- asp.net - 在 asp.net core 3 Web 应用程序中针对 HttpPost 方法的 jSon 大摇大摆地显示用户参数值
- python - 为什么不能在熊猫的 for 循环中使用 loc(index+1,'col name')?
- java - 如何返回具有不同元素类型的相同通用集合类型?