#Help with SlashCommandBuilder Error
43 messages · Page 1 of 1 (latest)
you didnt set the description of the option
Oh
After setting it, I can't run the command
it isnt showing up
ah
Still aren't showing up
show the updated code
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)
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
im not that familiar with using module.exports
ye
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
i dont get it
its thoroughly explained here
i dont know what you did
I ran the commands stuff as a separate file
then closed the terminal and ran the bot in a new terminal
show that file
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);
}
});
can you see the command in that guild
nope