addition

part of index.js
client.on('interactionCreate', (interaction) => {

if (interaction.commandName === 'add') {
const num1 = interaction.options.get('first-number').value;
const num2 = interaction.options.get('second-number').value;
const num3 = interaction.options.get('third-number')?.value;
const num4 = interaction.options.get('fourth-number')?.value;
const num5 = interaction.options.get('fifth-number')?.value;
const num6 = interaction.options.get('sixth-number')?.value;
const num7 = interaction.options.get('seventh-number')?.value;
const num8 = interaction.options.get('eight-number')?.value;
const num9 = interaction.options.get('nineth-number')?.value;

interaction.reply(`The sum is ${num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9}`);
}
}
client.on('interactionCreate', (interaction) => {

if (interaction.commandName === 'add') {
const num1 = interaction.options.get('first-number').value;
const num2 = interaction.options.get('second-number').value;
const num3 = interaction.options.get('third-number')?.value;
const num4 = interaction.options.get('fourth-number')?.value;
const num5 = interaction.options.get('fifth-number')?.value;
const num6 = interaction.options.get('sixth-number')?.value;
const num7 = interaction.options.get('seventh-number')?.value;
const num8 = interaction.options.get('eight-number')?.value;
const num9 = interaction.options.get('nineth-number')?.value;

interaction.reply(`The sum is ${num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9}`);
}
}
16 Replies
d.js toolkit
d.js toolkit8mo ago
- 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 OP
f(x) = 1/x
f(x) = 1/xOP8mo ago
part of register-commands.js
{
name: 'add',
description: 'adds two numbers',
options: [
{
name: 'first-number',
description: 'the first number to be added',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'second-number',
description: 'the second number to be added',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'third-number',
description: 'the third number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'fourth-number',
description: 'the fourth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'fifth-number',
description: 'the fifth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'sixth-number',
description: 'the sixth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'seventh-number',
description: 'the seventh number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'eighth-number',
description: 'the eighth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
}, no space for ninth in discord
{
name: 'add',
description: 'adds two numbers',
options: [
{
name: 'first-number',
description: 'the first number to be added',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'second-number',
description: 'the second number to be added',
type: ApplicationCommandOptionType.Number,
required: true,
},
{
name: 'third-number',
description: 'the third number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'fourth-number',
description: 'the fourth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'fifth-number',
description: 'the fifth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'sixth-number',
description: 'the sixth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'seventh-number',
description: 'the seventh number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
},
{
name: 'eighth-number',
description: 'the eighth number to be added',
type: ApplicationCommandOptionType.Number,
required: false,
}, no space for ninth in discord
ShompiFlen
ShompiFlen8mo ago
why is this in #djs-voice
f(x) = 1/x
f(x) = 1/xOP8mo ago
result: The sum is NaN oh- i haven't noticed it mb mb mb
ShompiFlen
ShompiFlen8mo ago
you are adding numbers with null how is that supposed to work
f(x) = 1/x
f(x) = 1/xOP8mo ago
then what do i do for optional numbers
ShompiFlen
ShompiFlen8mo ago
nevermind you can in fact add numbers with null in javascript
f(x) = 1/x
f(x) = 1/xOP8mo ago
;-;
Spaxter
Spaxter8mo ago
I also already told you to use getNumber here
f(x) = 1/x
f(x) = 1/xOP8mo ago
i did .value it worked well
ShompiFlen
ShompiFlen8mo ago
use the number getter as told
Spaxter
Spaxter8mo ago
Why not just use getNumber?
ShompiFlen
ShompiFlen8mo ago
at least try it
f(x) = 1/x
f(x) = 1/xOP8mo ago
.?value okay one min worked but why didn't .value work
Spaxter
Spaxter8mo ago
The difference is that getNumber gives you null which is 0 when added, while ?.value gives you undefined which will be NaN when added
f(x) = 1/x
f(x) = 1/xOP8mo ago
got it sir! thanks
Want results from more Discord servers?
Add your server