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)

2 Answers

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")
1

How to get a Role by Name

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest