不一致JS-不一致APIError:缺少访问

Discord JS - DiscordAPIError: Missing Access(不一致JS-不一致APIError:缺少访问)

本文介绍了不一致JS-不一致APIError:缺少访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我按照破损的按键教程进行了调试,我不知道问题出在哪里,以下是错误

/home/container/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
      ^
    
DiscordAPIError: Missing Access
    at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
    at async GuildApplicationCommandManager.create (/home/container/node_modules/discord.js/src/managers/ApplicationCommandManager.js:117:18) {
  method: 'post',
  path: '/applications/901999677011005472/guilds/905266476573950023/commands',
  code: 50001,
  httpStatus: 403,
  requestData: {
    json: {
      name: 'ping',
      description: 'Bot uptime/latency checker.',
      type: undefined,
      options: undefined,
      default_permission: undefined
    },
    files: []
  }
}

我还尝试查看代码,但没有发现错误。

这是我的代码,我真的认为代码有问题。

const DiscordJS = require('discord.js')
const { Intents } = require('discord.js')
const dotenv = require('dotenv')
dotenv.config()
    
const client = new DiscordJS.Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES
    ]
})
    
client.on('ready', () => {
    console.log("The bot is online")
    // Carlos: 883425101389914152
    const guildId = '905266476573950023'
    const guild = client.guilds.cache.get(guildId)
    let commands
        
    if (guild) {
        commands = guild.commands
    } else {
        commands = client.application.commands
    }
        
    commands.create({
        name: 'ping',
        description: 'Bot uptime/latency checker.',
    })
        
    commands.create({
        name: 'add',
        description: 'Adds two numbers given by user.',
        options: [
            {
                name: 'number1',
                description: 'The first number',
                required: true,
                type: DiscordJS.Constants.ApplicationCommandOptionTypes.NUMBER,
            },
            {
                name: 'number2',
                description: 'The second number',
                required: true,
                type: DiscordJS.Constants.ApplicationCommandOptionTypes.NUMBER,
            },
        ]
    })
})
    
client.on('interactionCreate', async (interaction) => {
    if (!interaction.isCommand()) {
        return
    }
        
    const { commandName, Options } = interaction
        
    if (commandName === 'ping') {
        interaction.reply({
            content: 'Pong! **60ms**',
            // If anyone can see = True, Only command user can see = False
            ephemeral: true,
        })
    } else if (commandName === 'add') {
        interaction.reply({
            content: 'The sum is ${number1 + number2}'
        })
    }
})
  
client.login(process.env.KEY)

推荐答案

您在为不一致服务器创建僵尸登录链接时没有选择正确的权限。

转到开发人员/OAuth再次单击BOT,然后选择您在此BOT中使用的所有必需权限。

然后复制生成的链接,并使用它与您的机器人一起登录到您的服务器。

这篇关于不一致JS-不一致APIError:缺少访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:不一致JS-不一致APIError:缺少访问

基础教程推荐