python - 当被提及时,如何使用 discord.py 中的机器人回复 Discord 频道上的消息?
问题描述
非常坚持这个 - 这是这里的代码:
'如果提到机器人'似乎没有变化 - 任何解决方案?
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
if client.user.mentioned_in(message) and 'Hi' in message.content:
await message.channel.send('_Solara hooman_ :wink:')
else:
return
client = MyClient()
解决方案
您应该使用self.user
而不是client
. 这应该有效:
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
if self.user.mentioned_in(message) and 'Hi' in message.content:
await message.channel.send('_Solara hooman_ :wink:')
else:
return
现在,如果您 ping 机器人并说Hi
(区分大小写),它应该会响应。
推荐阅读
- clojure - 为什么 conj 可以产生比通常预期相反的结果
- javascript - 为什么 var mysql = require('mysql'); 返回未定义
- javascript - 一个选择上的 jQuery onchange 函数,ajax 填充辅助选择。如何改回默认值?
- amazon-web-services - 为什么我无法从我的机器连接到 rds db
- redirect - IIS 将子目录重定向到同名的根级目录
- python - 从模块 main 中运行单个测试
- c - 从文件读取字节顺序
- python - Python 3.7 类实例的静态字典
- javascript - 是的,条件对象验证不起作用
- c++ - 如何在 C++ 中检查 char 数组是否包含任何没有循环的字符?