I am making a Discord Bot with python, and right now I am making a command where the bot repeats your input if certain requirements are met. Full code for that command is here (I added commentation). I am working on sanitizing the input, and one part of that checks if there is any bad words used in the input.
The input is a tuple, I made it like that so I can show the first 5 words that were said.
So I want to check if any of those BADWORD_triggers are used in the input, currently I am doing it like this: elif ' '.join(args) in BADWORD_triggers
However that only checks if the first word is one of the triggers. I also tried elif args in BADWORD_triggers
and elif BADWORD_triggers in args
which just results in errors.
For other commands I use def async function(ctx, *, arg)
where I can check if the input contains any of the BADWORD_triggers like this: if arg in BADWORD_triggers:
because *, arg
is a string.
So my question is concretely: How do I check if a tuple contains anything from a list.
Example:
Here is I use a badword "bad" as the only and first input, the bot refuses to say it. However I want it to also refuse this, as it contains a bad word. https://i.sstatic.net/BGquq.jpg
Here I use a badword "bad" but with more input, the message gets deleted and the bot repeats what I say. https://i.sstatic.net/c36IY.jpg
You could write a simple function
:
def check_bad_words(words):
for word in words:
if word in BADWORD_triggers:
return True
return False
and then in your elif-statement
:
elif check_bad_words(args):
pass