【发布时间】:2021-03-08 01:07:22
【问题描述】:
最近,我的机器人在更改了与这段代码完全无关的内容后决定停止工作。
当我要求它向消息的作者 (message.author.send()) 发送消息时,它会发送通知,但实际上没有消息出现。我得到带有 1 个 ping 徽章的机器人图标,但是当我单击时,无法读取新消息。以下是相关代码:
async def on_message(self, Message):
print('Scanning message')
blacklisted_words = [
# I won't show these here for obvious reasons
]
offendingwords = []
cursefound = False
for cursecheck in blacklisted_words:
if cursecheck in Message.content.lower():
cursefound = True
offendingwords.append(cursecheck)
if cursefound == True:
print('Found curse word, user notified\n')
await Message.delete()
words = []
for word in offendingwords:
words.append(word)
await Message.author.send(f'Please watch your language in <#{Message.channel.id}>!\nOffending word(s) - `{str(words)}`')
cursefound = False
else:
print('No curse words found\n')
请原谅我糟糕的格式,我对 Python 还是很陌生。
它还会抛出一个 AttributeError:
await Message.author.send(f'Please watch your language in <#{Message.channel.id}>!\nOffending word(s) - `{str(words)}`')
AttributeError: 'ClientUser' object has no attribute 'send'
请尽量简化这一点,我太容易混淆了。谢谢!
【问题讨论】:
标签: python url-rewriting notifications discord discord.py