Answer the question
In order to leave comments, you need to log in
Why is the bot not working as planned?
I decided to write a code to filter the chat. The bottom line is this: there is a black list of words, and a white list of words, and they are accompanied by a white list of roles (roles that the bot should not respond to, even if they wrote something from the black list of words).
The problem itself: at the moment, two roles from the white list of roles are specified in the code, but the bot continues to delete messages, as if there is no such thing as "white_list_roles". But if one role is specified, then everything works.
Also, a special thanks will be if you tell me how to integrate the case check into this code.
@client.event
async def on_message(message):
black_list=["нига","негр"]
white_list=["книга","неграмотный"]
white_list_role1=discord.utils.get(message.guild.roles, name="Модератор")
white_list_role2=discord.utils.get(message.guild.roles, name="Администратор")
white_list_roles=[white_list_role1,white_list_role2]
for roles in white_list_roles:
if roles in message.author.roles:
pass
else:
if message.content in black_list:
await message.delete()
elif message.content in white_list:
pass
Answer the question
In order to leave comments, you need to log in
You can simply check as the intersection of two sets
if set(white_list_roles) & set(message.author.roles):
# я админ, могу ругаться
else:
# я холоп, ругаться нельзя
if any(bad_word in message.content for bad_word in black_list):
await message.delete()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question