我遇到了一个问题,如果消息中有 2 个脏话,它会发送 2 个嵌入。有没有人知道解决这个问题?
@client.event
async def on_message(message):
for bad_word in bad_words:
if bad_word in message.content.lower().split(" "):
t = discord.Embed(color=0x039e00, title="Message Removed", description=f":x: Please don't say that here, {message.author.mention}.")
t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
await message.channel.send(embed=t, delete_after=5)
await message.delete()
else:
await client.process_commands(message)
答案 0 :(得分:2)
只需在 break
后添加一个 await message.delete()
即可跳出 bad_words
for 循环:
@client.event
async def on_message(message):
for bad_word in bad_words:
if bad_word in message.content.lower().split(" "):
# ...
await message.delete()
break
else:
await client.process_commands(message)