【问题标题】:How to give own bot permission to see categories?如何授予自己的机器人查看类别的权限?
【发布时间】:2021-04-28 20:52:18
【问题描述】:

我的机器人有一个创建类别的命令,其中包含一个文本和语音通道。在创建类别时,我会覆盖仅允许特定角色查看该类别及其频道的权限。

在此之前一切正常。当我希望我的机器人看到文本通道时,我的问题就出现了,这样他就可以阅读消息并与之交互。除了 Discord 应用程序之外,我的机器人没有任何额外的作用。

到目前为止,这是我尝试过的解决方案:

  • 将 Bot 设置为 Administrator:此解决方案有效,但想放弃它,因为我不知道是否建议将您的 bot 设置为管理员,并且我认为应该有其他方法来解决这个问题。
  • 向类别添加权限,设置我的机器人角色以让他读取和写入消息,如下所示:
await category.set_permissions(bot_role, read_messages=True, send_messages=True, connect=True)

这会引发 discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access 错误,我不明白,因为我在我的 oauth 页面中设置了所有权限(见下图)。 我也尝试为文本通道提供相同的权限,但它会引发相同的错误。

我真正想要的只是让我的 Bot 阅读该文本频道中的消息,因为如果 Bot 看不到该频道,他将不会响应任何命令。

编辑: 这就是我创建类别和频道的方式:

async def prepare_game(ctx):
    guild = ctx.guild
    role = await guild.create_role(name=role_name)
    category = await guild.create_category('Game')
    await category.set_permissions(role, read_messages=True, send_messages=True, connect=True, speak=True)
    text_channel = await guild.create_text_channel('Board', category=category, sync_permissions=True)
    voice_channel = await guild.create_voice_channel('Room', category=category, sync_permissions=True)

最后,我添加了await category.set_permissions(bot_role, read_messages=True, send_messages=True, connect=True)line,其中bot_role 是我的应用程序机器人角色

【问题讨论】:

  • 你能补充一下你是如何创建频道的吗?
  • 我用命令更新了问题
  • 我的代码没有问题吗?我的机器人可以看到频道。

标签: python-3.x discord.py


【解决方案1】:

尝试为ctx.guild.me(机器人用户本身)设置权限覆盖。

docsset_permissions 将接受角色或成员。

例如:

async def prepare_game(ctx):
    guild = ctx.guild
    role = await guild.create_role(name=role_name)
    category = await guild.create_category('Game')
    await category.set_permissions(role, read_messages=True, send_messages=True, connect=True, speak=True)
    await category.set_permissions(ctx.guild.me, read_messages=True, send_messages=True, speak=True)
    text_channel = await guild.create_text_channel('Board', category=category, sync_permissions=True)
    voice_channel = await guild.create_voice_channel('Room', category=category, sync_permissions=True)

【讨论】:

  • 不错。我不知道ctx.guild.me 指向的是机器人而不是触发命令的成员。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-20
  • 2014-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
相关资源
最近更新 更多