0
votes

I'm working on a discord.py bot, no problems, my code just works fine, but i wanted to know how to give bot owner's permissions, he should remove a role that gives all high permissions, (all the permissions that are in Server>Server settings>roles>role name) so he should remove his role, but he gives this error:

discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

@bot.command(name="godRemove")
async def godremover(ctx, persona, numerogod):
    channel = bot.get_channel(id=786285288469037197)
    numerogod=int(numerogod)
    if not numerogod>1:
        numerogod=1
    #hasadded=False
    #hasgod=False
    rolenumber=0
    try:
        guild=ctx.guild
        if ctx.author.name in canAddGod:
            for i in guild.members:
                if str(i)[:-5].lower().strip()==persona.lower().strip():
                    for role in i.roles:
                        #if str(role)=="God":
                            #hasgod=True
                        if representsint(str(role)):
                            rolename=str(int(str(role))-numerogod).strip().lower()
                            rolenumber=int(rolename)
                            if rolenumber>1:
                                if discord.utils.get(ctx.guild.roles, name=rolename)!=None:
                                    togiverole=discord.utils.get(guild.roles, name=rolename)
                                    await i.add_roles(togiverole)
                                    await i.remove_roles(role)
                                    #hasadded=True
                                    await channel.send(removedliteral)
                                    return
                                else:
                                    togiverole=await ctx.guild.create_role(name=str(int(str(role))+numerogod), colour=discord.Colour(0xFFFFFF))
                                    await i.add_roles(togiverole)
                                    await i.remove_roles(role)
                                    #hasadded=True
                                    await channel.send(removedliteral)
                                    return
                            elif rolenumber==0:
                                await i.remove_roles(discord.utils.get(ctx.guild.roles, name="God"))
                            else:
                                await i.remove_roles(discord.utils.get(ctx.guild.roles, name="God"))
                                await i.remove_roles(role)
    except Exception:
        traceback.print_exc()
        await channel.send(errorliteral)

The code is a bit messup, but is been a while that i dont code in python, so here a little explaination (ps, this is a little funny thing that i want to add to my server, like, everyone is a god, if they do something funny i add gods, if not i remove gods, so if they dont have enough gods (<0) i will remove the real God role, who gives permissions): i get the channel where i should send the messages i get the number of gods to remove i set rolenumber to 0, then i get the guild, if the name is in the peoples that can do this, for every member i'll search for persona, who is the member to remove gods from then, if the role is a int that means i found the role i want to modify, if the number of his gods is more than 1, i will so remove gods like, if is 27 and i remove 20 it will possibily create a new role or give a already created one, if is 0 it will remove the number role, and if is <0 then i want to remove the "God" role, who gives permissions.

ANSWER: Move the role who should have more permissions higher than the role who should be "dominated" in the roles list!

1

1 Answers

3
votes

discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions means the bot failed to do something because of the bot's permissions. This is separate from the bot owner, which is another user with independent permissions.

You need to give the bot permission to do whatever action you are performing. This is done in your server/guild config.

If you are writing commands that only a bot owner can do, there is a decorator called is_owner in Discord.py