command name is invalid
hi guys i get this error its my first time making slash command bot and i just cloned that code from a github repo
throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Invalid Form Body
options[0].name: Command name is invalid
at RequestHandler.execute (D:\CODING\Discord bot\discord-slash-bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (D:\CODING\Discord bot\discord-slash-bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async Client.<anonymous> (D:\CODING\Discord bot\discord-slash-bot\app.js:14:3) {
method: 'post',
path: '/applications/1191799930591916122/commands',
code: 50035,
httpStatus: 400
}
throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Invalid Form Body
options[0].name: Command name is invalid
at RequestHandler.execute (D:\CODING\Discord bot\discord-slash-bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (D:\CODING\Discord bot\discord-slash-bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async Client.<anonymous> (D:\CODING\Discord bot\discord-slash-bot\app.js:14:3) {
method: 'post',
path: '/applications/1191799930591916122/commands',
code: 50035,
httpStatus: 400
}
2 Replies
- 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!
- ✅
Marked as resolved by staffconst { Client, APIMessage } = require("discord.js");
const { readdirSync } = require("fs");
const Bot = new Client();
const Config = require("./config");
const Commands = [];
const cmdFiles = readdirSync("./commands").filter((file) =>
file.endsWith(".js"),
);
Bot.on("ready", async () => {
for (const fileName of cmdFiles) {
const File = require(`./commands/${fileName}`);
Commands.push(File);
await Bot.api.applications(Bot.user.id).commands.post({
data: {
name: File.name,
description: File.description,
options: File.options,
},
});
}
console.info(`Logged in as ${Bot.user.username}`);
});
Bot.ws.on("INTERACTION_CREATE", (interaction) => {
const CMDFile = Commands.find(
(cmd) => cmd.name.toLowerCase() === interaction.data.name.toLowerCase(),
);
if (CMDFile)
CMDFile.execute(Bot, say, interaction, interaction.data.options);
});
Bot.login(Config.token);
async function say(interaction, content) {
return Bot.api
.interactions(interaction.id, interaction.token)
.callback.post({
data: {
type: 4,
data: await createAPIMessage(interaction, content),
},
});
}
async function createAPIMessage(interaction, content) {
const apiMessage = await APIMessage.create(
Bot.channels.resolve(interaction.channel_id),
content,
)
.resolveData()
.resolveFiles();
return { ...apiMessage.data, files: apiMessage.files };
}
const { Client, APIMessage } = require("discord.js");
const { readdirSync } = require("fs");
const Bot = new Client();
const Config = require("./config");
const Commands = [];
const cmdFiles = readdirSync("./commands").filter((file) =>
file.endsWith(".js"),
);
Bot.on("ready", async () => {
for (const fileName of cmdFiles) {
const File = require(`./commands/${fileName}`);
Commands.push(File);
await Bot.api.applications(Bot.user.id).commands.post({
data: {
name: File.name,
description: File.description,
options: File.options,
},
});
}
console.info(`Logged in as ${Bot.user.username}`);
});
Bot.ws.on("INTERACTION_CREATE", (interaction) => {
const CMDFile = Commands.find(
(cmd) => cmd.name.toLowerCase() === interaction.data.name.toLowerCase(),
);
if (CMDFile)
CMDFile.execute(Bot, say, interaction, interaction.data.options);
});
Bot.login(Config.token);
async function say(interaction, content) {
return Bot.api
.interactions(interaction.id, interaction.token)
.callback.post({
data: {
type: 4,
data: await createAPIMessage(interaction, content),
},
});
}
async function createAPIMessage(interaction, content) {
const apiMessage = await APIMessage.create(
Bot.channels.resolve(interaction.channel_id),
content,
)
.resolveData()
.resolveFiles();
return { ...apiMessage.data, files: apiMessage.files };
}
module.exports = {
name: "say",
description:"Say command.",
options: [
{
name: "Text",
description: "You can print something on the bot.",
type: 3,
required: true,
},
],
async execute(_bot, say, interaction, args) {
await say(interaction, args[0].value);
},
};
module.exports = {
name: "say",
description:"Say command.",
options: [
{
name: "Text",
description: "You can print something on the bot.",
type: 3,
required: true,
},
],
async execute(_bot, say, interaction, args) {
await say(interaction, args[0].value);
},
};