首页 > 解决方案 > 无法注册斜线命令。获取丢失访问错误

问题描述

尝试将斜杠命令添加到我的公会时,我遇到了丢失的访问错误。我已经踢了机器人,删除了机器人并改变了意图。我的意向号码是 32265

在此处输入图像描述

这是我添加命令的代码:

const commandFiles = await globPromise(`${process.cwd()}/commands/**/*.js`);
const arrayOfSlashCommands = [];
commandFiles.map((value) => {
     const file = require(value);
     const splitted = value.split("/");
     const directory = splitted[splitted.length - 2];

     if (file.name) {
         const properties = { directory, ...file };
         client.commands.set(file.name, properties);

         arrayOfSlashCommands.push(file);
     }
});

client.on("ready", () => {
     client.guilds.cache.get("783606158669381663").commands.set(arrayOfSlashCommands);
});

但我收到了这个错误:

E:\Development\DiscordBot\Dc_v1_13_FeatureTest\node_modules\discord.js\src\rest\RequestHandler.js:298
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Missing Access
    at RequestHandler.execute (E:\Development\DiscordBot\Dc_v1_13_FeatureTest\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (E:\Development\DiscordBot\Dc_v1_13_FeatureTest\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
    at async GuildApplicationCommandManager.set (E:\Development\DiscordBot\Dc_v1_13_FeatureTest\node_modules\discord.js\src\managers\ApplicationCommandManager.js:146:18) {
  method: 'put',
  path: '/applications/893555323200237599/guilds/783606158669381663/commands',
  code: 50001,
  httpStatus: 403,
  requestData: {
    json: [
      {
        name: 'search',
        description: 'Search',
        type: undefined,
        options: undefined,
        default_permission: undefined
      }
    ],
    files: []
  }
}

标签: discorddiscord.js

解决方案


解决方案是使用以下方法邀请机器人:

这些范围


推荐阅读