【发布时间】:2021-01-07 23:44:06
【问题描述】:
我的代码正在运行。只有一个问题,就是在调用任何命令之后,我的 on_message 都会被立即调用(这会导致一些副作用)
async def delete_on_swear(message):
if not message:
return
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
try:
guild_id = message.guild.id
except AttributeError:
return
cursor.execute(f'SELECT word FROM badwords WHERE guild_id={guild_id}')
swears = [swear[0] for swear in cursor.fetchall()]
if not swears:
return
if bot.user == message.author:
return
for swearword in swears:
if not message.channel.is_nsfw() and is_substring(message.content.lower(), swearword):
await message.delete()
await message.author.create_dm()
await message.author.dm_channel.send(
f'Hi {message.author}, you sent a message containing the following word: {swearword}'
)
return```
【问题讨论】:
-
为什么不呢?要使用机器人命令,用户输入一条消息,对吗?所以还有一条信息需要思考。
标签: python discord.py