Skip to content
Advertisement

Check if A role has perms – Discord.py

Here Is a Good question. I want to check all roles in a server for admin, then create a new channel and allow only those set roles to have access. I dont want to use @commands.has_guild_permissions().

Advertisement

Answer

If by roles with admin you mean any role that has the Administrator permission on (not just the server’s owner), then every time you create a new channel, they will have access to it. Meaning you don’t need to check for the roles if your only goal is to create the channel that only they can use. You would just have to set the default permissions to False, making the channel only accessible to people with Admin roles and Bots:

@client.command(pass_context=True)
async def admins_channel(ctx):
    guild = ctx.message.guild
    await guild.create_text_channel('cool-channel')
    channel = discord.utils.get(ctx.guild.channels, name='cool-channel')
    await channel.set_permissions(ctx.guild.default_role, send_messages=False, read_messages=False)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement