Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.78k stars 3.75k forks source link

Checking if message.author.top_role is upper than user.top_role in the role list #1941

Closed KubasPlay closed 5 years ago

KubasPlay commented 5 years ago

I want to create administrator commands but I don't know how to check if message author top role is upper than user top role or if they're on the same place. My code:

elif message.content.upper().startswith((prefix)+'BAN'): if message.author.server_permissions.ban_members: for user in message.mentions: msg = ':warning: You are banned!'.format(message) await client.send_message(user, msg) await client.ban(user) msg = ':white_check_mark: Success! Banned '+(user.name)+'#'+(user.discriminator)+'!'.format(message) await client.send_message(message.channel, msg)

I want to check before ban if message author top role is upper than mentioned user top role or if they're on the same place on the list.

zachsamuels commented 5 years ago

For one I would recommend looking into the commands extension if you are making commands instead of using on_message. And two, you can compare roles using binary operators.

Also, this is not an issue with discord.py. GitHub issues for this repository should be used to report issues with this library. They are not a medium for requesting help with Python. For further help specific to using this library, you should join either the official discord.py server or the Discord API server, as the README recommends.

TheRockettek commented 5 years ago

you can use ctx.guild.me.top_role > role to see if it is higher on the role list :T

Rapptz commented 5 years ago

Roles can be compared with comparator operators (i.e. <, >, >=, <=, etc).