I'm trying to make a discord bot that can be able to ban users but I'm running into a problem and it´s that, I want to check if the user is superior, like if it´s bannable or not checking whether the role that the user have is above the one who is trying to ban him but it isn't working. Is there something wrong with my logic?
#¿Is a user bannable?
95 messages · Page 1 of 1 (latest)
How's the roles set up
I mean, I'm experimenting, I don't want to ban the user that I mention, I just want the message to be sent, that´s why I commented the '.kick()' line
on the server?
Cause if the role of the bot is below other roles in the list, it won't be able to do anything to any user above them
Role1
Role2
Role3
BotRole
Role4
If the roles are like this, the bot will be able to only ban Role4
Nonon
The bot does ban people
But what if a moderator is trying to ban an admin?
Like
Admin > Moderator
Yes
Role clash
Mods can't ban admins as default
They're below admins in the hierarchy of role permissions
Exaclty
Bot has to have higher permissions to do that
But when I run the command as a lower rank the bot sends the message that I can ban them
What matters here isn't the rank/role of the person running the command
But the rank/role of the Bot, and the member it's trying to ban
If the bot has got moderator permissions, and not administrator permissions, it won't be able to ban any administrators
No matter who runs the command
What if it does?
Does it though?
yes
Ah
You have the bot banning wrong people?
Or you can't get it to ban people?
Okay I'm gonna try to explain it again
As you can see in my code, I'm checking if a user is bannable
And when a moderator wants to ban an administrator, the bot says it is bannable
Discord rank hierarchy for servers, if the rank is below a rank, it's bannable by anyone above:
Owner (Cannot be banned by people in the server)
Administrator (Only bannable by the Owner)
Moderator (Got moderating permissions, no "Administrator" permission)
Member
If your bot got Administrator role, they can ban any administrator
Yes, if your bot has got an Administrator role, they can ban other administrators, that is how it works on normal Discord servers without bots as well?
You'll have to check the person running the command and what their role is, instead of checking the bot role
If you don't want mods banning admins
the moderators
The bot got administrator permissions
Then you'll have to check that they aren't trying to ban anyone with administrator role
Bot will be able to do it, even if a normal member runs the command, cause the Bot got the admin permissions
You're thinking about this in a slightly wrong way
XD
You're thinking that it goes based on the person using the command
No, it's based on the Bot role and The member being banned
You'll have to code in the check to see that the command isn't used by anyone else but people it should be used by
Then add in additional checks that whoever is running the command can only ban people below them, even with the bot
How can I do that?
Do I have to specify every role? That doesn't sound right to me
How does the other bots do it?
Usually by limiting ban commands to a single trusted rank
But at the core, you can only check that if a person with a role named Moderator for example is trying to use the bot to ban someone with a different role, and prevent that if they are
Say you had these roles for staff:
Owner
Administrator (Bot belongs to this role)
Moderator
All 3 got Ban Members permissions
If the person running the ban has got Moderator role, disallow or prevent them from banning anyone with the role Administrator
Check the roles for the member running the command, and the member mentioned in the command
If the mentioned member is in the same group, or higher as the person running the ban command, prevent the ban
Okay okay okay okay got it
But now, The bot belongs to its own category
I mean, it has its role by default
Does that role have the Administrator permission turned on?
Yes!
Then they're exactly that
And it is at the top of everyone
In the hierarchy
Doesn't matter if you got 19237612786 other roles with Administrator permission
If the bot has got that permission, and is above the other roles, it can ban any role below them
If there's one Administrator rank you don't want to get banned
Move it above the bot role
Problem solved
That was the KEY
That´s what I went to try and it worked!
Thank you very much for the help!
Keep in mind that now the admin role can't be banned even by other people in the same group via the bot
Yes of course
That role essentially is now untouchable by the bot