Having choices as both strings and numbers for the same option?

I am trying to make an option for a slash command have a choices of one being a number and the other being a word/string. Is there a work around for this?
35 Replies
d.js toolkit
d.js toolkitā€¢16mo ago
ā€¢ What's your exact discord.js npm list discord.js and node node -v version? ā€¢ Post the full error stack trace, not just the top part! ā€¢ Show your code! ā€¢ Explain what exactly your issue is. ā€¢ Not a discord.js issue? Check out #useful-servers.
Munxo
Munxoā€¢16mo ago
options: [
{
name: 'id/ign',
description: 'Player ID or IGN',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'duration',
description: 'Duration of ban',
type: ApplicationCommandOptionType.String,
choices: [
{
name: 'Permanent',
type: ApplicationCommandOptionType.Number,
value: 0,
},
{
name: '1d',
type: ApplicationCommandOptionType.String,
value: '1d',
},
{
name: '3d',
type: ApplicationCommandOptionType.String,
value: '3d',
},
{
name: '7d',
type: ApplicationCommandOptionType.String,
value: '7d',
},
{
name: '30d',
type: ApplicationCommandOptionType.String,
value: '30d',
},
],
required: true,
},
options: [
{
name: 'id/ign',
description: 'Player ID or IGN',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'duration',
description: 'Duration of ban',
type: ApplicationCommandOptionType.String,
choices: [
{
name: 'Permanent',
type: ApplicationCommandOptionType.Number,
value: 0,
},
{
name: '1d',
type: ApplicationCommandOptionType.String,
value: '1d',
},
{
name: '3d',
type: ApplicationCommandOptionType.String,
value: '3d',
},
{
name: '7d',
type: ApplicationCommandOptionType.String,
value: '7d',
},
{
name: '30d',
type: ApplicationCommandOptionType.String,
value: '30d',
},
],
required: true,
},
Error: "There was an error: DiscordAPIError[50035]: Invalid Form Body 0.options[1].choices[0].value[STRING_TYPE_CONVERT]: Could not interpret "0" as string."
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Yeah, I was just testing to see if I could delegate those separately to fix my issue. Is there any work around to make it not "type: ApplicationCommandOptionType.String," and something that allows both strings and numbers to be the choices?
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Even if I do '0' instead of just 0, it still says it's not recognized as a string value. Okay, I didn't think it was possible. Thought to ask though.
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Of course. They always are. Autosave on VS Code is a lifesaver. Thank you for your time and the quick response. šŸ™‚ Have a good one!
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Actually. Wait! Can a String value be a space?
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
{
name: 'Permanent',
value: ' ',
},
{
name: 'Permanent',
value: ' ',
},
like so?
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Yeah, gave me the same error..
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
I'm creating an RCON ban command. This is the set up of the in game command: /ban (IGN or ID) (Duration: 0, 1m, 1h, 1d) (Admin Reason) (Player Reason) 0 bans forever, and so does leaving it blank So, "/ban munxo 0 test test" would ban me forever
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
and so would "/ban munxo test test" but this is how I'm sending the command to the game server:
conn.send(`/ban ${idign} ${duration} ${ign} ${reason}`);
conn.send(`/ban ${idign} ${duration} ${ign} ${reason}`);
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
I feel as though I need to use an "if" or an "else" somehow.
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docsā€¢16mo ago
mdn switch The switch statement evaluates an expression, matching the expression's value against a series of case clauses, and executes statements after the first case clause with a matching value, until a break statement is encountered. The default clause of a switch statement will be jumped to if no case matches the expression's value.
Munxo
Munxoā€¢16mo ago
client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'ban') {

const conn = new Rcon(process.env.HOST1_IP, process.env.HOST1_PORT, process.env.HOST1_PASS);
const idign = interaction.options.get('id/ign').value;
const duration = interaction.options.get('duration').value;
const ign = interaction.options.get('ign').value;
const reason = interaction.options.get('reason').value;

conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/ban ${idign} ${duration} ${ign} ${reason}`);
}).on('response',
function(str) {
console.log("Response: " + str);
interaction.reply(`**Server 1:** ` + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});

conn.connect();
}});
client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'ban') {

const conn = new Rcon(process.env.HOST1_IP, process.env.HOST1_PORT, process.env.HOST1_PASS);
const idign = interaction.options.get('id/ign').value;
const duration = interaction.options.get('duration').value;
const ign = interaction.options.get('ign').value;
const reason = interaction.options.get('reason').value;

conn.on('auth', function() {
console.log("Authenticated");
console.log("Sending command.")
conn.send(`/ban ${idign} ${duration} ${ign} ${reason}`);
}).on('response',
function(str) {
console.log("Response: " + str);
interaction.reply(`**Server 1:** ` + str);
}).on('error', function(err) {
console.log("Error: " + err);
}).on('end', function() {
console.log("Connection closed");
});

conn.connect();
}});
That is the code to send a command straight to the server.
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Game server
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
const commands = [
{
name: 'ban',
description: 'Bans a player in game.',
options: [
{
name: 'id/ign',
description: 'Player ID or IGN',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'duration',
description: 'Duration of ban',
type: ApplicationCommandOptionType.String,
choices: [
{
name: 'Permanent',
value: '0',
},
{
name: '1d',
value: '1d',
},
{
name: '3d',

value: '3d',
},
{
name: '7d',
value: '7d',
},
{
name: '30d',
value: '30d',
},
],
required: true,
},
{
name: 'ign',
description: 'Player IGN',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'reason',
description: 'Reasoning for ban',
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
const commands = [
{
name: 'ban',
description: 'Bans a player in game.',
options: [
{
name: 'id/ign',
description: 'Player ID or IGN',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'duration',
description: 'Duration of ban',
type: ApplicationCommandOptionType.String,
choices: [
{
name: 'Permanent',
value: '0',
},
{
name: '1d',
value: '1d',
},
{
name: '3d',

value: '3d',
},
{
name: '7d',
value: '7d',
},
{
name: '30d',
value: '30d',
},
],
required: true,
},
{
name: 'ign',
description: 'Player IGN',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'reason',
description: 'Reasoning for ban',
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
That is the slash command I have built for the Discord bot But that gives me DiscordAPIError[50035]: Invalid Form Body
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
There was an error: DiscordAPIError[50035]: Invalid Form Body 0.options[0].name[STRING_TYPE_REGEX]: String value did not match validation regex.
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
I'll change that now @JĆ“ šŸŒˆ šŸ¦„ ofc that was the issue.. I was fully overlooking that and didn't even think twice about it... My commands registered succesfully now..
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
I kept seeing 0's in the error and figured it was something wrong with the '0' for the permanent.
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
Munxo
Munxoā€¢16mo ago
Yeah, so '0' words as the string
Want results from more Discord servers?
Add your server