Iwkwbsbabaja
Iwkwbsbabaja

Reputation: 71

Get Role by name (discord.py Rewrite)

I have a problem with my Discord Bot. I want to create a text channel with read permissions for a Supporter Role, but I don't want to use the role_id. So, I tried to use the following code, but I can't create any channel.

          supporter_role = discord.utils.get("Supporter")
            overwrites = {
            supporter_role: discord.PermissionOverwrite(read_messages=True), guild.default_role: discord.PermissionOverwrite(read_messages=False), author: discord.PermissionOverwrite(read_messages=True)
          }
          channel = await guild.create_text_channel(name='║Ticket - {}'.format(authorname), overwrites=overwrites)

Upvotes: 6

Views: 11525

Answers (2)

RyZe OG
RyZe OG

Reputation: 11

How to get a Role by Name

Mod = discord.utils.get(ctx.guild.roles, name="Mods")

Upvotes: 1

Blue Guy
Blue Guy

Reputation: 125

The function discord.utils.get takes an iterable and searches for a matching item in the iterable. Since you haven't specified the iterable, the get function doesn't really know where to match the given name.

Hence you'll have to specify guild.roles as the first argument.

discord.utils.get(guild.roles,name="Supporter")

Upvotes: 7

Related Questions