我的代码正在运行。只有一个问题,那就是在调用任何命令之后,我的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```
答案 0 :(得分:1)
on_message
在机器人可以查看的任何频道中发送任何消息后运行。在您的on_message
的顶部,放置以下代码,以防止漫游器根据自己的消息进行操作:
if message.author == bot.user:
return