Reputation: 1
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
Reputation: 1207
you need to use discord.Permissions
class discord.Permissions(permissions=0, kwargs)
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
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