【问题标题】:Discord.js DiscordAPIError: Missing Permissions ---Which permission is missing?Discord.js DiscordAPIError: Missing Permissions --- 缺少哪个权限?
【发布时间】:2021-06-29 21:55:00
【问题描述】:

我有一个机器人,它应该在特定类别下创建一个频道,然后将两个用户添加到该频道。

以下代码“假定”可以工作并添加用户 2,但由于 DiscordAPIError: Missing Permissions 而失败。 我不知道这是实际所需的权限?

function addUserToChannel(ch, user, altCh) {
  console.log(user.username,"sendmsg",ch.permissionsFor(client.user).has("MANAGE_CHANNELS", false)); //returns true
  if (!ch.permissionsFor(user).has("SEND_MESSAGES", false)) {
    console.log("User", user.username, "lacks view-channel permission");
    ch.updateOverwrite(user, { //fails here obviously
      SEND_MESSAGES: true,
      VIEW_CHANNEL: true
    });
  } else {
    console.log("WARN:", user.username, " already in channel ", ch.name);
    altCh.send(user.toString() + " join conversation here: " + ch.toString());
  }
}

使用以下代码创建频道:

function createPrivateChannel(guild, convo, user) {
  let everyoneRole = guild.roles.cache.find(r => r.name === "@everyone");
  
  let parent = guild.channels.cache.find(ch => {
    //console.log(ch.id,secret.convoCat.id);
    return ch.id == secret.convoCat.id;
  });
 
  return guild.channels.create(convo.chName, {
    type: "text",
    parent: parent,
    permissionOverwrites: [
      {
        id: everyoneRole.id, //private channel
        deny: ["VIEW_CHANNEL", "SEND_MESSAGES"]
      }, 
      {
        id: client.user.id, //bot permissions
        allow: [  "VIEW_CHANNEL",  "SEND_MESSAGES",  "READ_MESSAGE_HISTORY",  "MANAGE_CHANNELS" ]
      },
      {
        id: user.user.id, //a different user
        allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"]
      }
    ]
  });
}

【问题讨论】:

  • 我添加了一个catch处理程序来处理错误消息,发现有一个错误代码:50013,如果有帮助的话

标签: discord discord.js


【解决方案1】:

根据Discord documentation for the 'Edit Channel Permissions' route(这是updateOverwrite 最终使用的):

需要MANAGE_ROLES 权限。只能允许/拒绝您的机器人在公会或频道中拥有的权限(除非您的机器人在频道中有 MANAGE_ROLES 覆盖)。

【讨论】:

  • 显然“MANAGE_CHANNEL”的含义与我理解的不同......
猜你喜欢
  • 2020-06-08
  • 2020-07-16
  • 2021-01-01
  • 2021-11-29
  • 1970-01-01
  • 2021-12-18
  • 2021-08-23
  • 1970-01-01
  • 2022-01-16
相关资源
最近更新 更多