【发布时间】:2020-09-23 08:57:16
【问题描述】:
我目前正在使用 discord.py 库编写一个不和谐机器人,我希望我的机器人在检测到消息中的单词而不检查大写字母时做出特定反应。
我已经找到了一个类来做到这一点,但是由于未知的原因,当我使用这个类时,机器人没有检测到消息中的字符串,他只在单独的消息时检测到它。 ..
这是我找到的课程:
class CaseInsensitively(object):
def __init__(self, s):
self.__s = s.lower()
def __hash__(self):
return hash(self.__s)
def __eq__(self, other):
try:
other = other.__s
except (TypeError, AttributeError):
try:
other = other.lower()
except:
pass
return self.__s == other
这是类的用法:
@client.event
async def on_message(message):
test = "Test"
if CaseInsensitively(test) in {CaseInsensitively(message.clean_content)}:
await discord.Message.add_reaction(message, "????")
await client.process_commands(message)
我在 ubuntu 16.04 上使用 python 3.7.1。
【问题讨论】:
-
您在这里也使用了错误的类。
await discord.Message.add_reaction(message, "????")应该是await message.add_reaction(react)
标签: python python-3.x discord.py