Someone2549652
Someone2549652

Reputation: 1

how to edit role permissions with discord.py rewrite?

I have a little problem. I want my bot to create a 'Muted' role when it joins a server. To achieve this, I have written this code:

@client.event
async def on_guild_join(guild):
        with open('prefixes.json', 'r') as f:
                prefixes = json.load(f)


        prefixes[str(guild.id)] = "b!"

        with open("prefixes.json", "w") as f:
                json.dump(prefixes, f, indent=4)

        await guild.create_role(name="Muted")
        for role in guild.roles:
                if role.name == "Muted":
                        await role.edit(reason = None, colour = discord.Colour.orange(), read_messages = True, read_message_history = True, connect = True, speak = True, send_messages = False)

This code correctly creates the role and correctly set the colour. However, it set none of the role's permissions.

Could anyone help me with this issue ?

Upvotes: 0

Views: 7256

Answers (2)

Billy
Billy

Reputation: 1207

Permissions class

you need to use discord.Permissions

class discord.Permissions(permissions=0, kwargs)

Example

permissions = discord.Permissions()
permissions.update(kick_members = False)
await role.edit(reason = None, colour = discord.Colour.blue(), permissions=permissions)

learn more here https://discordpy.readthedocs.io/en/latest/api.html#permissions :)

Upvotes: 1

Patrick Haugh
Patrick Haugh

Reputation: 60984

You need to pass a Permissions argument to the permissions argument of edit

perms = Permissions()
perms.update(read_messages = True, read_message_history = True, connect = True, speak = True, send_messages = False)
await role.edit(reason = None, colour = discord.Colour.orange(), permissions=perms)

Upvotes: 1

Related Questions