【问题标题】:Discord JS - DiscordAPIError: Missing AccessDiscord JS - DiscordAPIError:缺少访问权限
【发布时间】:2021-12-18 07:50:04
【问题描述】:

所以我按照不和谐机器人的磨损钥匙教程,我不知道问题是什么,这是错误


    /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)

如果你知道答案,请加我,ZellMC#9165

我希望有人回答这个问题,我真的需要它。提前谢谢你!!!

【问题讨论】:

    标签: javascript typescript discord discord.js


    【解决方案1】:

    为您的不和谐服务器创建机器人登录链接时,您没有选择正确的权限。

    再次转到开发人员/oauth,单击机器人并选择您在此机器人中使用的所有必需权限。

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

    【讨论】:

    • 我应该添加管理员权限吗?
    • 不是真的,除非你特别需要它
    • [Pterodactyl Daemon]: ---------- 检测到服务器进程处于崩溃状态! ---------- Pterodactyl Daemon]:退出代码:1 [Pterodactyl Daemon]:内存不足:false
    • 如果他们的回答解决了您的问题,请务必勾选它
    • @Zell 很高兴告诉我们您是如何解决问题的。您的修复可以像您在此处寻求帮助一样帮助其他人
    猜你喜欢
    • 2021-11-29
    • 2021-01-01
    • 2019-09-17
    • 1970-01-01
    • 2021-06-29
    • 2021-01-20
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多