Python discord.py:缺少访问错误为什么以及如何修复它?(找到解决方案)

Python discord.py:缺少访问错误为什么以及如何修复它?(找到解决方案),python,discord.py,Python,Discord.py,最后的解决方案 我试着做一个机器人,做临时工。语音频道。所有命令都可以正常工作,但当我“锁定”频道,这样就没有人可以再加入时,所有管理频道或管理频道权限的命令就不再工作了 锁定频道的代码: #第381行 permstemplock={ ctx.guild.default_角色:discord.PermissionOverwrite(connect=False), ctx.guild.me:discord.PermissionOverwrite(查看频道=True,管理角色=True, 管理\u通

最后的解决方案

我试着做一个机器人,做临时工。语音频道。所有命令都可以正常工作,但当我“锁定”频道,这样就没有人可以再加入时,所有管理频道或管理频道权限的命令就不再工作了

锁定频道的代码:

#第381行
permstemplock={
ctx.guild.default_角色:discord.PermissionOverwrite(connect=False),
ctx.guild.me:discord.PermissionOverwrite(查看频道=True,管理角色=True,
管理\u通道=真,管理\u权限=真),
ctx.author:discord.PermissionOverwrite(manage\u channels=True,connect=True,view\u channel=True),
}
等待临时编辑(覆盖=permstemplock)
另一个命令,用于管理频道的权限(在本例中为解锁):

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
错误:

Ignoring exception in command voice:
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.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:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\channel.py", line 694, in edit
    await self._edit(options, reason=reason)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\abc.py", line 309, in _edit
    data = await self._state.http.edit_channel(self.id, reason=reason, **options)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\http.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:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.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
解决方案: Bot需要权限
connect
。如果您有相同的问题,请设置
connect=True

来自:发生错误时将抛出。换句话说,你的机器人无法访问频道。这可能是因为频道正在将权限与类别同步,该类别正在禁用bot及其所需的权限

您可以通过设置角色perm或类别perm层次结构来解决此问题,以便bot可以访问创建的所有频道


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

好的,谢谢,我一到家就会测试它。但我有一个问题。您说过可能的原因是,
ctx.guild.default\u角色
ctx.guild.me
之前,并且它正在锁定bot权限。这个命令是这样的。但是,如果bot必须再次更改权限,我们会遇到与以前相同的问题,不是吗?bot需要perm
connect
,那么。。。
Ignoring exception in command voice:
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.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:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\channel.py", line 694, in edit
    await self._edit(options, reason=reason)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\abc.py", line 309, in _edit
    data = await self._state.http.edit_channel(self.id, reason=reason, **options)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\http.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:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.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