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 toolkit2y 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
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
Actually. Wait! Can a String value be a space?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
{
name: 'Permanent',
value: ' ',
},
{
name: 'Permanent',
value: ' ',
},
like so?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
Yeah, gave me the same error..
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
I feel as though I need to use an "if" or an "else" somehow.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2y 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
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
Game server
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
I kept seeing 0's in the error and figured it was something wrong with the '0' for the permanent.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Munxo
MunxoOP2y ago
Yeah, so '0' words as the string
Want results from more Discord servers?
Add your server