Some issue with the code that doesn't allow the creation of slash command error code 400

discord.js slash command
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});

const BOT_TOKEN = 'YOUR_BOT_TOKEN';

const commands = [
{
name: 'ping',
description: 'Ping pong!',
options: [
{
name: 'secret',
description: 'Secret code',
type: 'STRING',
required: true,
},
],
},
];

client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);

// Register slash commands globally
const application = await client.application.fetch();
await application.commands.set(commands);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName, options } = interaction;

if (commandName === 'ping') {
const secretOption = options.getString('secret');

if (secretOption === 'secretcode') {
await interaction.reply('Pong!');
} else {
await interaction.reply('Bong!');
}
}
});

client.login(BOT_TOKEN);
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});

const BOT_TOKEN = 'YOUR_BOT_TOKEN';

const commands = [
{
name: 'ping',
description: 'Ping pong!',
options: [
{
name: 'secret',
description: 'Secret code',
type: 'STRING',
required: true,
},
],
},
];

client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);

// Register slash commands globally
const application = await client.application.fetch();
await application.commands.set(commands);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName, options } = interaction;

if (commandName === 'ping') {
const secretOption = options.getString('secret');

if (secretOption === 'secretcode') {
await interaction.reply('Pong!');
} else {
await interaction.reply('Bong!');
}
}
});

client.login(BOT_TOKEN);
29 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna10mo ago
Show your error Also, you need to specify the type with the correct enum which is ApplicationCommandOptionType
gamer50082
gamer5008210mo ago
? sadly i work on mobile so will a screenshot do?
treble/luna
treble/luna10mo ago
Your 'type' property needs to be an enum Not a string Also dont deploy your commands on every start, use a deploy script
gamer50082
gamer5008210mo ago
so number 3 rate limit issues?
d.js docs
d.js docs10mo ago
guide Creating Your Bot: Registering slash commands read more
treble/luna
treble/luna10mo ago
It might get your ratelimited yes I dont know, hence why i say use the enum
gamer50082
gamer5008210mo ago
wait so when deployed does it automatically work with other server if deployed once like global
treble/luna
treble/luna10mo ago
If you use the global route, yes
gamer50082
gamer5008210mo ago
ah i see do u need logs or no?
treble/luna
treble/luna10mo ago
Not atm because the 400 is likely due to your incorrect type, if it persists, then yes
gamer50082
gamer5008210mo ago
yes the error return the type is 0
treble/luna
treble/luna10mo ago
did you use the enum
gamer50082
gamer5008210mo ago
yes bruh it works oh wrong script i used the index.js instead of bot.js lol node . becomes to comfortable nope error
treble/luna
treble/luna10mo ago
you should just have to run node deploy-commands.js Show it
gamer50082
gamer5008210mo ago
that would require me to take out the deployment code
treble/luna
treble/luna10mo ago
thats what the script is indeed made for to not run at every start
gamer50082
gamer5008210mo ago
treble/luna
treble/luna10mo ago
show your updated code And i dont see you using the enum, rather a string
gamer50082
gamer5008210mo ago
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});

const BOT_TOKEN = 'Aworkingtoken';

const commands = [
{
name: 'ping',
description: 'Ping pong!',
options: [
{
name: 'secret',
description: 'Secret code',
type: '3',
required: true,
},
],
},
];

client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);

// Register slash commands globally
const application = await client.application.fetch();
await application.commands.set(commands);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName, options } = interaction;

if (commandName === 'ping') {
const secretOption = options.getString('secret');

if (secretOption === 'secretcode') {
await interaction.reply('Pong!');
} else {
await interaction.reply('Bong!');
}
}
});

client.login(BOT_TOKEN);
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});

const BOT_TOKEN = 'Aworkingtoken';

const commands = [
{
name: 'ping',
description: 'Ping pong!',
options: [
{
name: 'secret',
description: 'Secret code',
type: '3',
required: true,
},
],
},
];

client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);

// Register slash commands globally
const application = await client.application.fetch();
await application.commands.set(commands);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName, options } = interaction;

if (commandName === 'ping') {
const secretOption = options.getString('secret');

if (secretOption === 'secretcode') {
await interaction.reply('Pong!');
} else {
await interaction.reply('Bong!');
}
}
});

client.login(BOT_TOKEN);
treble/luna
treble/luna10mo ago
yeah use the enum or actual numbers
gamer50082
gamer5008210mo ago
i did didn't i?
treble/luna
treble/luna10mo ago
No, thats a string
gamer50082
gamer5008210mo ago
oh i see that's wh
treble/luna
treble/luna10mo ago
Just use ApplicationCommandOptionType.String, or just 3 without '', if you can remember the types from memory
gamer50082
gamer5008210mo ago
it works 0-0 i read the docs but i didn't know '' was the cause welp it's time for me to come clean i used chatgpt ok it's solved well if the code 99% works it ok
treble/luna
treble/luna10mo ago
that does explain your issue Never ever use chatgpt for djs It uses data from 2021
gamer50082
gamer5008210mo ago
i am surprised the flag didn't cause any issues cause it has been
treble/luna
treble/luna10mo ago
Instead learn actual js instead of asking chatgpt
Want results from more Discord servers?
Add your server
More Posts
`fetchStarterMessage()` doesnt give me the first message of the threadI am trying to get the first message associated with the thread. But the message object returned frochannel.send('content'); error ponying to .sendTypeError: Cannot read properties of undefined (reading 'send') i am trying to send a message to a cChannelNotCached Error when make thread## Version discord.js - 14.12.1 node js - 18.6.0 ## Question I got an error when I try to make a thrGetting User Guild Avatar/BannerHi I'd like to know how can i get the user's avatar and banner in the current guild Currently I getGuildMember.setNickname weird issueIm using a modal for my discords verify system, where they input text and that text then becomes theMultiple Schema creation on message for level???So basically I have the leveling system and on the surface it seems to work, but there is just a fewGetting "Unknown interaction" error even with interaction.deferReply()Hey folks, I am getting a strange error with this code: ```ts class StandingsInteraction { publUnknown Interaction on awaitModalSubmit()Hi everyone, im kinda scratching my head here trying to figure out whats going on. https://pastebin.member.dmChannel.awaitMessages() breaking when updating from v14.11 to v14.12I currently have the following code which works perfectly in discord.js v14.11 however when I upgradUpdating an embed following interaction with a buttonHello, I have an embed with 2 buttons, a first which validates and a second which cancels. I would l