Search code examples
pythondiscorddiscord.pybotsroles

How do I make my Bot Ignore messages from people with a certain role? (Discord.py)


How can I make my Discord.py bot ignore messages from people that have a certain role?

I have recently added a feature that to my Discord.py bot.

@client.event
async def on_message(message):

    if message.content == "Blocked Word":
        await message.delete()

I want it so that if someone such has myself, has a certain role the bot will not delete the message.

Any help would be appreciated!


Solution

  • Here is some simple code, that might answer your question: This builds on @Joshua Nixon's answer

    @client.event()
    async def on_message(message):
     if 'role' in [role.name for role in message.author.roles]: #checks if the specified role is in the user's roles
       #do something
     else:
       #do something else