Trying to add a subcommand with SlashCommandBuilders i get this error.
FULL ERROR(very long):
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Invalid Form Body
11.options[0]: Field "type" is required to determine the model type.
at RequestHandler.execute (C:UsersstixyDocumentsBD-1node_modulesdiscord.jssrcrestRequestHandler.js:350:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (C:UsersstixyDocumentsBD-1node_modulesdiscord.jssrcrestRequestHandler.js:51:14)
at async GuildApplicationCommandManager.set (C:UsersstixyDocumentsBD-1node_modulesdiscord.jssrcmanagersApplicationCommandManager.js:162:18)
at async Client.<anonymous> (C:UsersstixyDocumentsBD-1handlerindex.js:46:9) {
method: 'put',
path: '/applications/1119579539610284062/guilds/975834098549522462/commands',
code: 50035,
httpStatus: 400,
requestData: {
json: [
{
name: 'ban',
name_localizations: undefined,
description: 'Ban anybody in the server',
description_localizations: undefined,
type: undefined,
options: [
{
type: 6,
name: 'user',
name_localizations: undefined,
name_localized: undefined,
description: 'The user you want to ban',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
},
{
type: 3,
name: 'reason',
name_localizations: undefined,
name_localized: undefined,
description: 'The reason you want to ban someone',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'echo',
name_localizations: undefined,
description: 'echos your message!',
description_localizations: undefined,
type: undefined,
options: [
{
type: 3,
name: 'message',
name_localizations: undefined,
name_localized: undefined,
description: 'the message you want to echo',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
},
{
type: 6,
name: 'user',
name_localizations: undefined,
name_localized: undefined,
description: 'a user you want to send the message to(not required)',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'kick',
name_localizations: undefined,
description: 'Kick anybody in the server',
description_localizations: undefined,
type: undefined,
options: [
{
type: 6,
name: 'user',
name_localizations: undefined,
name_localized: undefined,
description: 'The user you want to kick',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
},
{
type: 3,
name: 'reason',
name_localizations: undefined,
name_localized: undefined,
description: 'The reason you want to kick someone',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'purge',
name_localizations: undefined,
description: 'Purge messages in the channel you are currently in',
description_localizations: undefined,
type: undefined,
options: [
{
type: 4,
name: 'amount',
name_localizations: undefined,
name_localized: undefined,
description: 'How many messages you want to purge.',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'softban',
name_localizations: undefined,
description: 'Ban and immediately unban a user to delete their messages and kick them',
description_localizations: undefined,
type: undefined,
options: [
{
type: 6,
name: 'user',
name_localizations: undefined,
name_localized: undefined,
description: 'Who you want to softban',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
},
{
type: 3,
name: 'reason',
name_localizations: undefined,
name_localized: undefined,
description: 'The reason you want to ban the user',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'timeout',
name_localizations: undefined,
description: 'Timeout anybody in the server',
description_localizations: undefined,
type: undefined,
options: [
{
type: 6,
name: 'user',
name_localizations: undefined,
name_localized: undefined,
description: 'The user you want to timeout',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
},
{
type: 3,
name: 'length',
name_localizations: undefined,
name_localized: undefined,
description: 'The amount of time you want to timeout someone.',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
},
{
type: 3,
name: 'reason',
name_localizations: undefined,
name_localized: undefined,
description: 'The reason you want to timeout someone',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'unban',
name_localizations: undefined,
description: 'Unban a member this is currently banned',
description_localizations: undefined,
type: undefined,
options: [
{
type: 3,
name: 'userid',
name_localizations: undefined,
name_localized: undefined,
description: 'The user you want to unban',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'luke',
name_localizations: undefined,
description: 'Get informaton for Luke Skywalker.',
description_localizations: undefined,
type: undefined,
options: [
{
type: 5,
name: 'ephemeral',
name_localizations: undefined,
name_localized: undefined,
description: 'Make the command only visibale to you.',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'ping',
name_localizations: undefined,
description: 'returns websocket ping',
description_localizations: undefined,
type: 1,
options: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'spam',
name_localizations: undefined,
description: 'Spam Lxsiz to fucking hell',
description_localizations: undefined,
type: undefined,
options: [
{
type: 4,
name: 'value',
name_localizations: undefined,
name_localized: undefined,
description: 'How many times you want to spam lxsiz because the cunt isnt answering',
description_localizations: undefined,
description_localized: undefined,
required: true,
autocomplete: undefined,
choices: undefined,
options: undefined,
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'avatar',
name_localizations: undefined,
description: undefined,
description_localizations: undefined,
type: 2,
options: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'user',
name_localizations: undefined,
description: 'User category',
description_localizations: undefined,
type: undefined,
options: [
{
type: undefined,
name: 'info',
name_localizations: undefined,
name_localized: undefined,
description: 'idek',
description_localizations: undefined,
description_localized: undefined,
required: false,
autocomplete: undefined,
choices: undefined,
options: [],
channel_types: undefined,
min_value: undefined,
max_value: undefined,
min_length: undefined,
max_length: undefined
}
],
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'whois',
name_localizations: undefined,
description: undefined,
description_localizations: undefined,
type: 2,
options: undefined,
default_permission: undefined,
default_member_permissions: undefined,
dm_permission: undefined
}
],
files: []
}
}
Node.js v18.16.0
I seriously dont know why im getting this error according to tutorials im doing everything right. I know that type is undefined and thats why im getting an error, but i dont know why type is undefined as all the youtubers and even the docs do it like i have it setup in my command. Also yes i am using discord.jsv13 there is no particular reason besides im way too lazy to switch over to v14.
COMMAND:
const { SlashCommandBuilder, SlashCommandSubcommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");
module.exports = {
...new SlashCommandBuilder()
.setName("user")
.setDescription("User category")
.addSubcommand((subcommand) =>
subcommand
.setName("info")
.setDescription("Get information about a user")),
/**
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {string[]} args
*/
run: async (client, interaction, args) => {
},
};
Slash Command Handeling:
// Slash Command Handling
if (interaction.isCommand()) {
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({ content: "An error has occured " });
const args = [];
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
const command = cmd
if(command.permission) {
const authorPerms = interaction.channel.permissionsFor(interaction.member);
if(!authorPerms || !authorPerms.has(command.permission)) {
const err = new MessageEmbed()
.setDescription("Im sorry but you do not have the permissions to use this command")
.setColor("RED")
await interaction.deferReply({ephemeral: true})
return interaction.followUp({embeds: [err]}).then((sent) => {
setTimeout(() => {
sent.delete
}, 5000);
})
}
}
cmd.run(client, interaction, args);
}
2
Answers
Basically instead of using SlashComamndBuilder i used the default way of creating slash commands in which you define types and such.
This gave me no errros although it is a tad more work. I unfortunetly still have not figured out why SlashCommandBuilder gives no type when using .addSubcommand.
I’m not sure what guide you were following, but the official guide shows a bit different of a structure from what you have here.
For example the command itself you have being spread into the exports plus a
run
function that accepts three arguments. The docs (and my past experience) show that the data is held on adata
member and therun
function should beexecute
accepting only theinteraction
and the command args.However, since you do the command handling yourself the name/args of the executing function of the command does not matter. I believe using
data
instead of spreading still does.Similarly, for the command handling you are using
client.slashCommands
which does not exist according to the docs. Is this something that you’ve setup somewhere else in your code that you’ve omitted? The official guide shows a setup more like this for handling commands:Some key notes here are using
client.commands
as well as ensuring youawait
the executing function of the command since it is async.I suspect the exact issue here probably lies in your loop over the
options
. However seeing as this either does not exist or is not documented it’s hard to say what the issue might be without the full code. Perhaps you are using some sort of custom wrapper tointeraction
that addsoptions
?