Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a Discord Role by Id

I'm making a Discord bot but just ran into a problem.

I want to modify a role. A specific role. I know how to do that with edit_role, but I need to get the Role object to edit it. Now, that's the problem.

How do I get a Role object by the role's id? Or can I use the id in the Role argument?

like image 996
Aimarekin Avatar asked Sep 22 '18 15:09

Aimarekin


People also ask

What is everyone role ID in Discord?

The ID for the everyone role is the Guild ID. Now to mention everyone, all you need is to send the string @everyone: message.channel. send("@everyone"); To obtain the ID for the everyone role, you need to have the guild, which you get on some events like: message , guildCreate , and others.

How do I automatically get a role in Discord?

In the Modules Settings section, click on the Autoroles option from the left side menu. In the main window, click on the drop-down and select the role you want to add for auto-assign. Choose the length of time necessary for new members to acquire this role in the Delay (minutes) box.

How do I copy a role ID in Discord mobile?

On Android press and hold the Server name above the channel list. You should see the last item on the drop-down menu: 'Copy ID'. Click Copy ID to get the ID.

How do I get a bot ID in Discord?

Follow these steps to find your Server ID: In Discord, open your User Settings by clicking the Settings Cog next to your user name on the bottom. Go to Appearance and enable Developer Mode under the Advanced section, then close User Settings. Open your Discord server, right-click on the server name, then select Copy ID.


2 Answers

You can use discord.utils.get to loop through Guild.roles and get the one you're looking for:

from discord.utils import get

role_id = 123
role = get(guild.roles, id=role_id)
like image 127
Patrick Haugh Avatar answered Oct 13 '22 11:10

Patrick Haugh


You can simply use Guild.get_role(role_id) to get the role if you have the id.

role_id = 2134532534
role = my_server.get_role(role_id)
like image 33
Sanjeevan Khanduri Avatar answered Oct 13 '22 11:10

Sanjeevan Khanduri