Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing role hierarchy with discord.py

I want to create a new role in discord.py.

But I want this role to be in the (let's say) 3rd spot of the roles. How can I achieve this?

like image 747
Keyinator Avatar asked Oct 14 '25 18:10

Keyinator


1 Answers

You would use Role.edit, passing a position value, which must be lower than the position of your highest role.

@bot.command()
async def moverole(ctx, role: discord.Role, pos: int):
    try:
        await role.edit(position=pos)
        await ctx.send("Role moved.")
    except discord.Forbidden:
        await ctx.send("You do not have permission to do that")
    except discord.HTTPException:
        await ctx.send("Failed to move role")
    except discord.InvalidArgument:
        await ctx.send("Invalid argument")
like image 112
Patrick Haugh Avatar answered Oct 17 '25 08:10

Patrick Haugh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!