I am trying to make a bad words system for my server's custom bot, but it seems to only listen for the first condition, ignoring the second one:
@bot.event
async def on_message(message):
###BAD WORDS CHECK
if message.author == bot.user:
pass
else:
if (any(x in message.content.lower() for x in words2)):
if "hack" or "crack" in message.content.lower():
await message.reply("I think you may be asking for illegal services or illegal advice. Please refer to rule #5 in the welcome channel!")
await message.channel.send("If you think this was a mistake please reply with $report!")
global CAN_REPORT
CAN_REPORT = "yes"
return
else:
pass
await bot.process_commands(message)
The bot will for some reason respond to any message containing any word from words2:
words2 = [
"instagram",
"snapchat",
"roblox",
"paypal",
"facebook",
"gmail",
"fortnite",
"minecraft",
"apex",
"youtube",
]
ignoring whether the message contains "hack", which leads to it replying to every message talking about social media or games. The goal is to check if BOTH conditions are true.
Any help is appreciated!
CodePudding user response:
With this line if "hack" or "crack" in message.content.lower():
you are basically checking if either the string "hack"
is true or if "crack" in message.content.lower()
is true.
Thus the check always returns true, because "hack"
will always be true.
The way to fix this would be something like this:
if "hack" in message.content.lower() or "crack" in message.content.lower():
Or, better yet, do it like you do in the first check:
word_list = ["hack", "crack"]
if any(x in message.content.lower() for x in word_list):
CodePudding user response:
Its simple just add :
if words2 in message.content.lower():
await message.delete()
await ctx.send('that word is banned')