好的,我在 discord.py 中做了一个反脏话系统,但你可以轻松绕过它。这是一个例子:假设“cat”是一个脏话,那么你可以只做“ccaatt”并且机器人不会检测到它。我该如何解决? 代码如下:
@client.event
async def on_message(message):
try:
if message.author.bot:
return
if client.user in message.mentions:
response = f"Hello! I'm Stealth Bot. My prefix is `-`. To see a list of commands do `-help`."
await message.channel.send(response)
print(f"{message.author.name} pinged me in {message.channel}!")
pass
if message.channel.id == 828667602351161354 or message.channel.id == 820049182860509206:
pass
else:
if profanity.contains_profanity(message.content):
await message.delete()
warnMessage = f"Hey {message.author.mention}! Don't say that!\n*You said ||{message.content}||*"
await message.channel.send(warnMessage, delete_after=5.0)
print(f"{message.author.name} tried saying: {message.content}")
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"{message.content}", inline=False)
embed.add_field(name="Debug:", value=f"{profanity}", inline=False)
embed.add_field(name="Debug 2:", value=f"{message.content.lower}", inline=False)
embed.add_field(name="Channel they tried to swear in:", value=f"<#{message.channel.id}>", inline=False)
await channel.send(embed=embed)
pass
await client.process_commands(message)
except Exception as e:
print(e)
答案 0 :(得分:3)
你可以试试这样的
def replaceDoubleCharacters(string):
lastLetter, replacedString = "", ""
for letter in string:
if letter != lastLetter:
replacedString += letter
lastLetter = letter
return replacedString
# your code
if profanity.contains_profanity(message.content) or profanity.contains_profanity(replaceDoubleCharacters(message.content)):
await message.delete()
# more of your code
replaceDoubleCharacters
完全按照它所说的去做。但是你应该记住,人们试图绕过限制是很常见的事情,他们会找到其他方法。
答案 1 :(得分:0)
我的做法是像这样使用 difflib
:
import difflib
swearWords = ["cat", "dog"]
swearWordsFound=difflib.get_close_matches("stringToCheck", swearWords)
答案 2 :(得分:-2)
做if swearword in message.content: message.delete
将检查消息内容是否包含该字符串