discord.py:无法解释的缺少访问权限错误



我试着做一个机器人,制作临时语音频道。有一个命令";锁";频道。意味着没有人可以再加入了。

锁定通道的代码:

# 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)

与锁定命令相反,解锁:

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)

机器人的服务器权限:

- 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

错误:

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

来自文档:发生状态代码403时抛出错误。换句话说,你的机器人无法访问该频道。这可能是因为通道正在将权限与禁用机器人程序所需权限的类别同步。

你可以通过设置角色perm或类别perm层次结构来解决这个问题,这样机器人就可以访问所有创建的频道。

另一个可能的原因是,您首先锁定了@everyone的权限,即锁定了机器人程序的权限。如果是这种情况,只需在ctx.guild.default_role行之前添加行ctx.guild.me

解决方案

Bot(ctx.guild.me(需要权限connect。做connect = True解决了问题:

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)

最新更新