Slash Command Question
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
name: 'data',
description: 'Commands related to user data.',
subcommands: [
new SlashCommandBuilder()
.setName('create')
.setDescription('Creates a new user account.'),
new SlashCommandBuilder()
.setName('delete')
.setDescription('Deletes all data of the specified user.')
.addStringOption(option => option.setName('user_id').setDescription('The ID of the user to delete data for.').setRequired(true)),
new SlashCommandBuilder()
.setName('showraw')
.setDescription('Shows all data of a specified user.')
.addStringOption(option => option.setName('user_id').setDescription('The ID of the user to show data for.').setRequired(true)),
],
async function dataCommand(client, interaction) {
// Get the subcommand name
const subcommandName = interaction.options.getSubcommand();
// Check if the subcommand name is valid
if (!subcommandName) {
// The user did not specify a subcommand
await interaction.reply('You need to specify a subcommand.');
return;
}
// Call the appropriate function based on the subcommand name
switch (subcommandName) {
case 'create':
await create(client, interaction);
break;
case 'delete':
await deleteUserData(client, interaction);
break;
case 'showraw':
await showraw(client, interaction);
break;
}
}
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
name: 'data',
description: 'Commands related to user data.',
subcommands: [
new SlashCommandBuilder()
.setName('create')
.setDescription('Creates a new user account.'),
new SlashCommandBuilder()
.setName('delete')
.setDescription('Deletes all data of the specified user.')
.addStringOption(option => option.setName('user_id').setDescription('The ID of the user to delete data for.').setRequired(true)),
new SlashCommandBuilder()
.setName('showraw')
.setDescription('Shows all data of a specified user.')
.addStringOption(option => option.setName('user_id').setDescription('The ID of the user to show data for.').setRequired(true)),
],
async function dataCommand(client, interaction) {
// Get the subcommand name
const subcommandName = interaction.options.getSubcommand();
// Check if the subcommand name is valid
if (!subcommandName) {
// The user did not specify a subcommand
await interaction.reply('You need to specify a subcommand.');
return;
}
// Call the appropriate function based on the subcommand name
switch (subcommandName) {
case 'create':
await create(client, interaction);
break;
case 'delete':
await deleteUserData(client, interaction);
break;
case 'showraw':
await showraw(client, interaction);
break;
}
}
/data <option_require>
option is create, delete, showraw. when select delete or showraw
// <option2>
will appear where i can input userid or something5 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 OPUnknown User•14mo ago
Message Not Public
Sign In & Join Server To View
ye i still not able to do it so, im testing around
which is wrong
i planned to replace first part with this
but it seem to break everything
still need help
so command i want is
const data = new SlashCommandBuilder()
.setName('data')
.setDescription('Commands related to user data.')
.addSubcommand(subcommand =>
subcommand
.setName('create')
.setDescription('Creates a new user account.')
.addSubcommand(subcommand =>
subcommand
.setName('delete')
.setDescription('Deletes all data of the specified user.')
.addUserOption(option => option.setName('target').setDescription('The user')))
.addSubcommand(subcommand =>
subcommand
.setName('showraw')
.setDescription('Shows all data of a specified user.')
.addUserOption(option => option.setName('target').setDescription('The user')));
const data = new SlashCommandBuilder()
.setName('data')
.setDescription('Commands related to user data.')
.addSubcommand(subcommand =>
subcommand
.setName('create')
.setDescription('Creates a new user account.')
.addSubcommand(subcommand =>
subcommand
.setName('delete')
.setDescription('Deletes all data of the specified user.')
.addUserOption(option => option.setName('target').setDescription('The user')))
.addSubcommand(subcommand =>
subcommand
.setName('showraw')
.setDescription('Shows all data of a specified user.')
.addUserOption(option => option.setName('target').setDescription('The user')));
/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:687
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50035]: Invalid Form Body
0.name[BASE_TYPE_REQUIRED]: This field is required
at handleErrors (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:687:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.runRequest (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:1072:23)
at async SequentialHandler.queueRequest (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:913:14)
at async _REST.request (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ApplicationCommandManager.set (/root/discord_bot/node_modules/discord.js/src/managers/ApplicationCommandManager.js:171:18) {
requestBody: {
files: undefined,
json: [
{
name: undefined,
name_localizations: undefined,
description: undefined,
nsfw: undefined,
description_localizations: undefined,
type: undefined,
options: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'ping',
name_localizations: undefined,
description: 'Replies with "pong!"',
nsfw: undefined,
description_localizations: undefined,
type: undefined,
options: undefined,
default_member_permissions: undefined,
dm_permission: undefined
}
]
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
'0': { name: { _errors: [ [Object] ] } }
}
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1044260619894931506/commands'
}
/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:687
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50035]: Invalid Form Body
0.name[BASE_TYPE_REQUIRED]: This field is required
at handleErrors (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:687:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.runRequest (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:1072:23)
at async SequentialHandler.queueRequest (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:913:14)
at async _REST.request (/root/discord_bot/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ApplicationCommandManager.set (/root/discord_bot/node_modules/discord.js/src/managers/ApplicationCommandManager.js:171:18) {
requestBody: {
files: undefined,
json: [
{
name: undefined,
name_localizations: undefined,
description: undefined,
nsfw: undefined,
description_localizations: undefined,
type: undefined,
options: undefined,
default_member_permissions: undefined,
dm_permission: undefined
},
{
name: 'ping',
name_localizations: undefined,
description: 'Replies with "pong!"',
nsfw: undefined,
description_localizations: undefined,
type: undefined,
options: undefined,
default_member_permissions: undefined,
dm_permission: undefined
}
]
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
'0': { name: { _errors: [ [Object] ] } }
}
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1044260619894931506/commands'
}
/data <option>
option is: create, delete, showraw. In delete and showraw command will have 1 more option /data <option1> <option2_optional>