所以我想检查消息中是否存在列表中的单词,所以我这样做了:
if any([x in message.content for x in List]):
但现在我也想检查一下我的列表中是否有一个单词不存在,但如果存在,它就不起作用。它只是忽略了黑名单
if any([x in message.content for x in List]) and not any([x in message.content for x in Blacklist]):
为什么会这样?
检查消息中是否有任何元素。你可以试试这个。
x = ['hello','there']
msg = 'hello sir'
wordsNotExistant = [words for words in msg.split(' ') if words not in x]
输出
['sir']
在x
中找不到的给定消息中的所有单词都将附加到wordNotExistant
中