discord.py: Inexplicable Missing Access error
Question:
I try to do a bot, who makes temporary Voice Channels. There’s a command which "locks" the channel. Means nobody can join anymore.
Code who locks the channel:
# line 381
permstemplock = {
ctx.guild.default_role: discord.PermissionOverwrite(connect=False),
ctx.guild.me: discord.PermissionOverwrite(view_channel=True, manage_roles=True,
manage_channels=True, manage_permissions=True),
ctx.author: discord.PermissionOverwrite(manage_channels=True, connect=True,view_channel=True),
}
await tempc.edit(overwrites=permstemplock)
And the opposite of the lock command, unlock:
permstempunlock = {
ctx.guild.me: discord.PermissionOverwrite(view_channel=True, manage_roles=True, manage_channels=True,
manage_permissions=True),
ctx.author: discord.PermissionOverwrite(manage_channels=True, connect=True,view_channel=True),
}
await tempc.edit(overwrites=permstempunlock)
Server permissions of the bot:
- Create Invite
- Manage Channels
- View Channels
- Send messages
- Manage messages
- Embed links
- Attached Files
- View message history
- Use external emojis
- Add reactions
- Move members
- Use Voice Activity
Error:
Ignoring exception in command voice:
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "F:/DiscordBot/PyCharm/AmongUsDeutsch/Tempchannels/tempchannels.py", line 381, in voice
await tempc.edit(overwrites=permstempunlock)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordchannel.py", line 694, in edit
await self._edit(options, reason=reason)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordabc.py", line 309, in _edit
data = await self._state.http.edit_channel(self.id, reason=reason, **options)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordhttp.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandsbot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50001): Missing Access
Answers:
From the docs: The error is thrown when status code 403 occurs. In other words, you’re bot doesn’t have access to the channel. This is probably because the channel is syncing permissions with the category which is disabling the bot its needed permissions.
You can fix this by setting up your role perm or category perm hierarchy so the bot will have access to all channels that are created.
Another possible cause is that you’re locking the permissions for @everyone first which is locking the bots permissions. If this is the case, just add the line ctx.guild.me before the ctx.guild.default_role line.
Solution
The Bot (ctx.guild.me
) needs the permission connect
. Doing connect = True
solved the problem:
permstemplock = {
ctx.guild.default_role: discord.PermissionOverwrite(connect=False),
ctx.guild.me: discord.PermissionOverwrite(view_channel=True, manage_roles=True,
manage_channels=True, manage_permissions=True, connect=True),
ctx.author: discord.PermissionOverwrite(manage_channels=True, connect=True,view_channel=True),
}
await tempc.edit(overwrites=permstemplock)
I try to do a bot, who makes temporary Voice Channels. There’s a command which "locks" the channel. Means nobody can join anymore.
Code who locks the channel:
# line 381
permstemplock = {
ctx.guild.default_role: discord.PermissionOverwrite(connect=False),
ctx.guild.me: discord.PermissionOverwrite(view_channel=True, manage_roles=True,
manage_channels=True, manage_permissions=True),
ctx.author: discord.PermissionOverwrite(manage_channels=True, connect=True,view_channel=True),
}
await tempc.edit(overwrites=permstemplock)
And the opposite of the lock command, unlock:
permstempunlock = {
ctx.guild.me: discord.PermissionOverwrite(view_channel=True, manage_roles=True, manage_channels=True,
manage_permissions=True),
ctx.author: discord.PermissionOverwrite(manage_channels=True, connect=True,view_channel=True),
}
await tempc.edit(overwrites=permstempunlock)
Server permissions of the bot:
- Create Invite
- Manage Channels
- View Channels
- Send messages
- Manage messages
- Embed links
- Attached Files
- View message history
- Use external emojis
- Add reactions
- Move members
- Use Voice Activity
Error:
Ignoring exception in command voice:
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "F:/DiscordBot/PyCharm/AmongUsDeutsch/Tempchannels/tempchannels.py", line 381, in voice
await tempc.edit(overwrites=permstempunlock)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordchannel.py", line 694, in edit
await self._edit(options, reason=reason)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordabc.py", line 309, in _edit
data = await self._state.http.edit_channel(self.id, reason=reason, **options)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordhttp.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandsbot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:UsersuserAppDataLocalProgramsPythonPython37libsite-packagesdiscordextcommandscore.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50001): Missing Access
From the docs: The error is thrown when status code 403 occurs. In other words, you’re bot doesn’t have access to the channel. This is probably because the channel is syncing permissions with the category which is disabling the bot its needed permissions.
You can fix this by setting up your role perm or category perm hierarchy so the bot will have access to all channels that are created.
Another possible cause is that you’re locking the permissions for @everyone first which is locking the bots permissions. If this is the case, just add the line ctx.guild.me before the ctx.guild.default_role line.
Solution
The Bot (ctx.guild.me
) needs the permission connect
. Doing connect = True
solved the problem:
permstemplock = {
ctx.guild.default_role: discord.PermissionOverwrite(connect=False),
ctx.guild.me: discord.PermissionOverwrite(view_channel=True, manage_roles=True,
manage_channels=True, manage_permissions=True, connect=True),
ctx.author: discord.PermissionOverwrite(manage_channels=True, connect=True,view_channel=True),
}
await tempc.edit(overwrites=permstemplock)