Skip to content
Advertisement

Discord.py read list

I have a file with a list called wbanned.txt which contains forbidden words. I want every message sent to be read and if it contains one of the forbidden words in the txt list (Every word is on a new line from list) to be deleted.

I tried something but all it does is delete it only if it contains the last word in the list.

The code:

JavaScript

The list:

JavaScript

So the program must accept this sentence: “This is example 1” But if you type: “This a banned member” this sentence need to be deleted.

Advertisement

Answer

.readlines() includes the trailing newlines, so you need to .strip() them.

Code(with some cleanup for best practices):

JavaScript

(Directly iterating over a file iterates line by line the same way .readlines() does, but without creating an unnecessary list)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement