python - 一旦对消息做出反应,如何让机器人向用户发送消息?
问题描述
我试图弄清楚on_reaction_add(message)
当用户对另一个玩家的消息做出反应时让机器人发送消息的功能中缺少什么。
@client.listen()
async def on_message(message):
"""
Looks for when a member calls 'bhwagon', and after 24 minutes, sends them a message
:param message: the message sent by the user
:return: a DM to the user letting them know their cooldown ended
"""
if message.content.startswith("bhwagon") or message.content.startswith("missed wagon"):
await cool_down_ended(message)
await on_reaction_add(message)
@client.event
async def on_reaction_add(message):
"""
Checks to see if there is a reaction on a message, and if there is, then send that user a message
:param message: represents the context in which a command is being invoked under
:return:
"""
if message.emoji == '882814250710626405': # If a certain reaction is used on a message
await message.author.send("message")
解决方案
我在这里看到一些对我没有意义的错误/事情。
on_reaction_add
没有message
参数,但取决于reaction
anduser
。await message.author.send()
总是会向消息的作者发送消息,而不是给做出反应的人,这是行不通的。您给定的 ID 似乎更像是消息 ID,而不是真正的 emoji-ID。
全局表情通常是这样构建的:
<:NAME:ID
- 这也是必须在代码中指定的方式。
Discord 中的表情符号可以轻松复制。
重要提示:所有表情符号必须在前面加上\
要复制的名称或表情符号。
根据我现在的信息,一个新的可能代码:
@client.event
async def on_reaction_add(reaction, user): # reaction & user as an argument
if reaction.emoji == '✅': # See if the reaction is the same as in the code
await user.send("message") # Send the user who reacted a message
!!请注意,您还为此启用了意图。对此做出了很好的贡献:StackOverflow 上的文档和答案!
推荐阅读
- android - 向列表视图添加第二个过滤器
- python - 用相同的键计算过去的条目
- package.json - 如何更新 package.json 依赖项?
- java - createEntityManagerFactory 在一台服务器上工作,但不在另一台服务器上工作
- mysql - MySQL 上的全文搜索,但词序必须很重要
- css - 设置 CSS 文件的过期时间
- amazon-web-services - 快速获取 AWS S3 对象元数据
- vba - excel-vba 如何使宏替换最后一个字符 5 并将其添加到新列中直到最后一行
- powershell - Azure 数据工厂在发布时禁用触发器
- python - 在 Python 中向正则表达式模式添加单个反斜杠