getInteger not working for one option but is working for another?

Basically, I have a dice roller bot and in a new command I'm working on, I can get one of my integers options but not the other. It fails with a TypeError: Cannot read properties of undefined (reading 'getInteger') Here is the code:
data: new SlashCommandBuilder() .setName('multiroll') .setDescription('Test command') .addIntegerOption(option => option.setName('times-to-roll') .setDescription('The number of times you would like the die rolled') .setRequired(true)) .addStringOption(option => option.setName('type-of-dice') .setDescription('The die roll to make') .setRequired(true)) .addIntegerOption(option => option.setName('mod') .setDescription('The modifier for the roll') .setRequired(false)), async execute(interaction) { const mult = interaction.options.getInteger('times-to-roll'); const string = interaction.options.getString('type-of-dice').toLowerCase(); const modifier = interaction.option.getInteger('mod', false) ?? 0; const rolls = [];
6 Replies
d.js toolkit
d.js toolkit3mo 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!
TaraHarkon
TaraHarkon3mo ago
TypeError: Cannot read properties of undefined (reading 'getInteger') at Object.execute (C:\Users\hilla\Code\tyche\commands\multiroll.js:23:39) at Client.<anonymous> (C:\Users\hilla\Code\tyche\index.js:45:17) at Client.emit (node:events:519:28) at Client.emit (node:domain:488:12) at InteractionCreateAction.handle (C:\Users\hilla\Code\tyche\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12) at module.exports [as INTERACTION_CREATE] (C:\Users\hilla\Code\tyche\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36) at WebSocketManager.handlePacket (C:\Users\hilla\Code\tyche\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31) at WebSocketManager.<anonymous> (C:\Users\hilla\Code\tyche\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12) at WebSocketManager.emit (C:\Users\hilla\Code\tyche\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:282:31) at WebSocketShard.<anonymous> (C:\Users\hilla\Code\tyche\node_modules@discordjs\ws\dist\index.js:1173:51)
This is the full stack trace
monbrey
monbrey3mo ago
Seems to be executing on the wrong type of interaction, it doesnt have options Or you've passed something in incorrectly, and it's not an interaction
TaraHarkon
TaraHarkon3mo ago
the first option ('times-to-roll') is working fine. Only 'mod' is failing and I'm not sure why. They're set up almost exactly the same way. The only difference is that 'mod' isn't required
monbrey
monbrey3mo ago
Oh, because of a typo, my bad options I mostly just read the error
TaraHarkon
TaraHarkon3mo ago
oh! thank you so much. I've been staring at this for about an hour trying to find the problem