#ok show me your code

1 messages · Page 1 of 1 (latest)

sharp dragon
#

Help

chrome whale
#

alr

#

each command looks a little like this

new Command({
    name: "help",
    aliases: [],
    details: {
        description: "Gives details about commands.",
        category: "Other"
    },
    slash: [
        {
            name: "command",
            description: "A specific command you want to learn more about.",
            required: false,
            
        }
    ],
    callback: (message,args,client) => { ... }
});
#

and I have an command handler which builds slash commands

#
const slash = [];
client.commands = new Discord.Collection();

fs.readdirSync("./commands/")
    .filter(file => file.endsWith(".js"))
    .forEach(file => {
        /**
         * @type {Command}
         */
        const cmd = require(`./commands/${file}`);
        client.commands.set(cmd.name,cmd);
        console.log(`Command ${cmd.name} loaded!`);
        
        const builder = new SlashCommandBuilder()
            .setName(cmd.name)
            .setDescription(cmd.details.description);
        cmd.slash.forEach(arg => {
            let option = new SlashCommandStringOption()
                .setName(arg.name)
                .setDescription(arg.description)
                .setRequired(arg.required);
            builder.addStringOption(option);
        });

        slash.push(builder);
    });
#

and i found code on discord.js guide which uses the discord rest api

const rest = new REST({version: 9}).setToken(process.env.DISCORD_BOT_TOKEN);

(async () => {
    try{
        await rest.put(
            Routes.applicationGuildCommands("871280132667604993","222078108977594368"),
            {body: slash}
        );
    } catch(err){
        console.error(err);
    }
})();
#

and the error i keep getting is this

DiscordAPIError[50001]: Missing Access
    at SequentialHandler.runRequest (/home/runner/InspireBot/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.js:198:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SequentialHandler.queueRequest (/home/runner/InspireBot/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.js:99:20)
    at async /home/runner/InspireBot/index.js:46:3 {
  rawError: { message: 'Missing Access', code: 50001 },
  code: 50001,
  status: 403,
  method: 'put',
  url: 'https://discord.com/api/v9/applications/871280132667604993/guilds/222078108977594368/commands'
}