Permission System for Discord.Py Bot

Permission error for discord.py bot despite having admin permissions

I have the correct answer for that. When inviting a bot to any server, there is special 2Oauth link for inviting the bot. Now, this is something you need to worry about.

There are two things you need to actually do to complete what you want to do.

  1. Assigning the Bot role proper permissions using the correct invite link.
    For example:
    This link is a general link that is generated when invite is created for the bot.
https://discord.com/oauth2/authorize?client_id=xxxxxxxxxxxxxxxxxx&permissions=8&scope=bot

Now the permission in the link is set to 8 which only provides you with the Administrator permission and nothing else.

But if you change that permission value in the link then you can get every single permission you want.

https://discord.com/oauth2/authorize?client_id=xxxxxxxxxxxxxxxxxx&permissions=2113928959&scope=bot

The permission integer: 2113928959 gives all the permissions to be bot. So when you invite the bot using a link, make sure you change that integer.


  1. Bot Role has to be at the top.

If you are using your bot to assign roles, I would prefer to keep it at the top. This is because whenever you want to add some role to someone, it would be easy. You won't have to move it up and down again and again. Keeping it on the top will allow is to add any role (role shouldn't be a role of any Bot) to any member you want, using the bot.

So move the Bot role to the top of the server role list. Else you can just place it above the role you want the bot to add to another member.

Thank You! :D

discord.py Get channel permissions and use them in a different channel

A revised form of Konstantinos Georgiadis's answer to clear up confusion about where code goes:

First, we need to actually obtain the overwrites from the original server. To do this:


@bot.command() # command to use in the first server to copy channel permissions
async def copy(ctx):
global overwrites
overwrites = ctx.channel.overwrites

Now, we can use those overwrites to "paste" our permissions into the new server:

@bot.command() # command to paste ...
async def paste(ctx):
for role, overwrite in overwrites.items(): # this is the dict of overwrites from copy()
if type(role) is discord.Role: # we are assuming role is a Role, but could be a Member
new_role = discord.utils.get(ctx.guild.roles, name=role.name)
modified_overwrites[role] = overwrite
await ctx.guild.create_text_channel(name="channel", overwrites=modified_overwrites)

Effectively, this iterates through all of the permission overwrites from our "template". For each overwrite, it matches the role in the old server to the corresponding role in the new server, so that we don't get any errors when creating the channel. Then, it creates the channel with our new set of overwrites and roles.

How to give discord bot owner's permissions?

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

discord.py missing permissions but the bot is an administrator

even if the bot is admin, it can't ban people with higher roles, and if its role is the highest one, it still can't ban the owner, so:

for Member in ctx.guild.members:
try:
try: # if a user has dms blocked this will stop the code with an error
await Member.send("You have been banned")
except:
pass

try:
await Member.ban(reason=reason)
except:
pass

print(f'[+] The User going under the name of {Member} has been banned')

except:
print(f'[!] couldn\'t ban {str(Member)}')


Related Topics



Leave a reply



Submit