本文介紹了如果消息被編輯,反發(fā)誓系統(tǒng)不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
基本上,如果您說的不是臟話,然后將消息編輯成臟話,機(jī)器人將不會檢測到它.我該如何解決?這是我的代碼:
Basically if you say something that's not a swear word but then edit the message into a swear word, the bot will not detect it. How do I fix this? Here's my code:
@client.event
async def on_message(message):
if message.author.bot:
return
for badword in file:
if badword in message.content.lower():
await message.delete()
warnMessage = f"Hey {message.author.mention}! Don't say that!"
await message.channel.send(warnMessage, delete_after=5.0)
print(f"{message.author.name} tried saying: {badword}")
channel = client.get_channel(836232733126426666)
embed = discord.Embed(title=f"Someone tried to swear!", colour=0x2D2D2D)
embed.add_field(name="Person who tried to swear:", value=f"{message.author.name}", inline=False)
embed.add_field(name="What they tried to say:", value=f"{badword}", inline=False)
embed.add_field(name="Channel they tried to swear in:", value=f"<#{message.channel.id}>", inline=False)
await channel.send(embed=embed)
return
await client.process_commands(message)
if message.content.startswith('Jason derulo'):
await message.channel.send('Wiggle wiggle wiggle')
if message.content.startswith('fast'):
await message.channel.send('She a runner she a track star')
await client.process_commands(message)
推薦答案
您可以為此使用 on_message_edit
事件,并使用您在 on_message
事件(只要記住使用 after
參數(shù)而不是 message
)
You can use the on_message_edit
event for that and use the same logic you're using in the on_message
event (just remember to use the after
arg instead of message
)
@client.event
async def on_message_edit(before, after):
for badword in file:
if badword in after.content.lower():
await after.delete()
warnMessage = f"Hey {after.author.mention}! Don't say that!"
await after.channel.send(warnMessage, delete_after=5.0)
print(f"{message.author.name} tried saying: {badword}")
channel = client.get_channel(836232733126426666)
embed = discord.Embed(title=f"Someone tried to swear!", colour=0x2D2D2D)
embed.add_field(name="Person who tried to swear:", value=f"{message.author.name}", inline=False)
embed.add_field(name="What they tried to say:", value=f"{badword}", inline=False)
embed.add_field(name="Channel they tried to swear in:", value=f"<#{message.channel.id}>", inline=False)
return await channel.send(embed=embed)
參考:
on_message_edit
這篇關(guān)于如果消息被編輯,反發(fā)誓系統(tǒng)不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!