#Help with SlashCommandBuilder Error

43 messages · Page 1 of 1 (latest)

royal kestrelBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

radiant turtle
#

you didnt set the description of the option

trail basin
#

it isnt showing up

radiant turtle
#

ids have to be strings

#

on Routes.applicationGuildCommands

trail basin
#

ah

trail basin
radiant turtle
#

show the updated code

trail basin
#
const Discord = require("discord.js");
const { REST } = require('@discordjs/rest');
const { Client, GatewayIntentBits, Partials, SlashCommandBuilder, Routes } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.DirectMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages ], partials: [Partials.Channel]});
const { token } = require('./token.json');

const rest = new REST({ version: '10' }).setToken(token);

client.on('ready', () =>{
    console.log(client.user.tag + " is now online!");
})

const testSlash = new SlashCommandBuilder()
    .setName("test")
    .setDescription("Test")
    .addStringOption(option =>
        option
        .setName("option_1")
        .setDescription("option_1_desc")
        .setRequired(true)
        .addChoices(
            {name: "value 1", value: "value_1"},
            {name: "value 2", value: "value_2"},
            {name: "value 3", value: "value_3"}
        )
        );

const commands = [testSlash.toJSON()];

(async () =>{
    try {
        await rest.put(
            Routes.applicationGuildCommands("1021159357007802368", "940438220959789097"),
            { body: commands }
        )
    } catch (error) {
        console.log(error);
    }
});

client.on('interactionCreate', (interaction) =>{
    if (interaction.isChatInputCommand()) {
        if (interaction.commandName == "test") {
            interaction.reply(interaction.options.get("option_1"))
        }
    }
})

client.login(token)
radiant turtle
#

btw, you dont have to create a rest instance and a discord.js Client in the same file

#

you should have a separate script for deploying the commands

trail basin
#

im not that familiar with using module.exports

radiant turtle
#

what for

#

a separate script that you'd run separately

trail basin
#

ye

radiant turtle
#

you're supposed to only deploy your commands once

#

and then you'd run that script again when you make changes to the details of a command

#

description/options, etc

trail basin
#

i dont get it

radiant turtle
#

its thoroughly explained here

trail basin
#

so this script runs separately

#

and it will be running constantly

radiant turtle
#

no

#

runs once, ever

trail basin
#

o

#

@radiant turtle Still doesn't

radiant turtle
#

i dont know what you did

trail basin
#

I ran the commands stuff as a separate file

#

then closed the terminal and ran the bot in a new terminal

radiant turtle
#

show that file

trail basin
#
const { REST } = require('@discordjs/rest');
const { Routes, SlashCommandBuilder } = require('discord.js');
const { token } = require('./token.json');

const rest = new REST({ version: '10' }).setToken(token);

const testSlash = new SlashCommandBuilder()
    .setName("test")
    .setDescription("Test")
    .addStringOption(option =>
        option
        .setName("option_1")
        .setDescription("option_1_desc")
        .setRequired(true)
        .addChoices(
            {name: "value 1", value: "value_1"},
            {name: "value 2", value: "value_2"},
            {name: "value 3", value: "value_3"}
        )
        );

const commands = [testSlash.toJSON()];

(async () =>{
    try {
        await rest.put(
            Routes.applicationGuildCommands("1021159357007802368", "940438220959789097"),
            { body: commands }
        )
    } catch (error) {
        console.log(error);
    }
});
radiant turtle
#

can you see the command in that guild

trail basin
radiant turtle
#

add some debug listeners to the rest instance

#
rest.on("rateLimited", console.log).on("restDebug", console.log);
#

add that after the const rest = ... line

trail basin
#

ok

#

nothing

#

logged

#

@radiant turtle