duration is null or undefined

when i do /addreminder 1s it just still says its undefined.
const { SlashCommandBuilder } = require("discord.js");
const ms = require("ms");

module.exports = {
data: new SlashCommandBuilder()
.setName("addreminder")
.setDescription("Adds a reminder")
.addStringOption((option) =>
option
.setName("duration")
.setDescription("When to remind you (e.g., 10s, 5m, 1h)")
.setRequired(true)
),
async execute(interaction) {
const duration = interaction.options.getString("duration");

if (!duration) {
console.error("Error: duration is null or undefined!!");
return interaction.reply({
content:
"No duration provided! Please provide a valid duration (e.g., 10s, 5m, 1h).",
ephemeral: true,
});
}

const msDuration = ms(duration);

if (!msDuration || isNaN(msDuration) || msDuration <= 0) {
return interaction.reply({
content:
"Invalid duration! Please provide a valid format (e.g., 10s, 5m, 1h).",
ephemeral: true,
});
}

return interaction.reply({
content: `Reminder set for ${duration}!`,
ephemeral: true,
});
},
};
const { SlashCommandBuilder } = require("discord.js");
const ms = require("ms");

module.exports = {
data: new SlashCommandBuilder()
.setName("addreminder")
.setDescription("Adds a reminder")
.addStringOption((option) =>
option
.setName("duration")
.setDescription("When to remind you (e.g., 10s, 5m, 1h)")
.setRequired(true)
),
async execute(interaction) {
const duration = interaction.options.getString("duration");

if (!duration) {
console.error("Error: duration is null or undefined!!");
return interaction.reply({
content:
"No duration provided! Please provide a valid duration (e.g., 10s, 5m, 1h).",
ephemeral: true,
});
}

const msDuration = ms(duration);

if (!msDuration || isNaN(msDuration) || msDuration <= 0) {
return interaction.reply({
content:
"Invalid duration! Please provide a valid format (e.g., 10s, 5m, 1h).",
ephemeral: true,
});
}

return interaction.reply({
content: `Reminder set for ${duration}!`,
ephemeral: true,
});
},
};
4 Replies
d.js toolkit
d.js toolkit2mo 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
constt 🎄❄
constt 🎄❄OP2mo ago
the 1s is a option /addreminder time:1s
constt 🎄❄
constt 🎄❄OP2mo ago
No description
constt 🎄❄
constt 🎄❄OP2mo ago
but why is it on discord time then and not duation works now, i needed to restart discord :skukll
Want results from more Discord servers?
Add your server