Skip to content
Advertisement

checking if message author has a certain role

I am making an automatic banning system with a discord bot. So once a message with a steam id is placed into the channel, it will run through an API and ban them (I’ve got this working)

what I am looking for is to check if that user has a certain role or not.

For this I am using a @client.listen("on_message") because the messages usually look like this “[steam id] hacker” and so discord ext wont work because its always looking for its prefix first.

so I am looking at like this:

if author.has_role(role_id_here):
   # do something

else:
   # do nothing

hopefully this is possible.

Advertisement

Answer

Well, you can either use the name of the role 'role' in list(role.name for role in message.author.roles)

But you want search by ID, so use roleID in list(role.id for role in message.author.roles)

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