#New to discord js v14 and am having some
1 messages · Page 1 of 1 (latest)
deploySlashCommands.js
const { REST, Routes } = require('discord.js');
const fs = require('node:fs');
const commands = [];
// Grab all the command files from the slashcommands directory you created earlier
const commandFiles = fs.readdirSync('./slashcommands').filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./slashcommands/${file}`);
commands.push(JSON.stringify(command.run.data));
console.log(JSON.stringify(command.run.data))
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(process.env.token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
console.log(commands)
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(process.env.clientId, process.env.guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();```
/slashcommands/test.js
```const { SlashCommandBuilder } = require('@discordjs/builders');
exports.run = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
exports.name = "test/cmd"```
Error
DiscordAPIError[50035]: Invalid Form Body
0[DICT_TYPE_CONVERT]: Only dictionaries may be used in a DictType
at SequentialHandler.runRequest (C:\Users\WaffleDevs\OneDrive\Documents\JS\mafiastyle\node_modules\@discordjs\rest\dist\index.js:667:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\WaffleDevs\OneDrive\Documents\JS\mafiastyle\node_modules\@discordjs\rest\dist\index.js:464:14)
at async REST.request (C:\Users\WaffleDevs\OneDrive\Documents\JS\mafiastyle\node_modules\@discordjs\rest\dist\index.js:910:22)
at async C:\Users\WaffleDevs\OneDrive\Documents\JS\mafiastyle\deploySlashCommands.js:25:16 {
requestBody: {
files: undefined,
json: [
'{"options":[],"name":"ping","description":"Replies with Pong!"}'
]
},
rawError: {
code: 50035,
errors: { '0': [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/763116571555659786/guilds/838488568959074316/commands'
}```
D.js 14.7.1