How to make SlashCommand Args

Trying to make an Integer arg for a slash command but it is giving me a weird error.
5 Replies
d.js toolkit
d.js toolkit17mo 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. - Issue solved? Press the button!
ig
igOP17mo ago
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('DeleteMessages')
.setDescription('Deletes the past messages of a specified amount.')
.addIntegerOption((option) => {
option.setName("Amount")
.setDescription("How many messages to delete.")
.setRequired(true) // error here
}),

async execute(interaction) {
interaction.channel.bulkDelete(interaction.options.getInteger("amount"))
await interaction.reply('Done!');
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('DeleteMessages')
.setDescription('Deletes the past messages of a specified amount.')
.addIntegerOption((option) => {
option.setName("Amount")
.setDescription("How many messages to delete.")
.setRequired(true) // error here
}),

async execute(interaction) {
interaction.channel.bulkDelete(interaction.options.getInteger("amount"))
await interaction.reply('Done!');
},
};
C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:47
throw this.error;
^

ExpectedConstraintError: Invalid string format
at Object.run (C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:1592:64)
at C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:212:66
at Array.reduce (<anonymous>)
at StringValidator.parse (C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:212:29)
at validateName (C:\Users\jorde\source\repos\mybot\node_modules\@discordjs\builders\dist\index.js:1402:17)
at MixedClass.setName (C:\Users\jorde\source\repos\mybot\node_modules\@discordjs\builders\dist\index.js:1499:5)
at Object.<anonymous> (C:\Users\jorde\source\repos\mybot\commands\testing\deleteMessages.js:5:10)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
constraint: 's.string.regex',
given: 'DeleteMessages',
expected: 'expected /^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}_-]+$/u.test(expected) to be true'
}
C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:47
throw this.error;
^

ExpectedConstraintError: Invalid string format
at Object.run (C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:1592:64)
at C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:212:66
at Array.reduce (<anonymous>)
at StringValidator.parse (C:\Users\jorde\source\repos\mybot\node_modules\@sapphire\shapeshift\dist\index.js:212:29)
at validateName (C:\Users\jorde\source\repos\mybot\node_modules\@discordjs\builders\dist\index.js:1402:17)
at MixedClass.setName (C:\Users\jorde\source\repos\mybot\node_modules\@discordjs\builders\dist\index.js:1499:5)
at Object.<anonymous> (C:\Users\jorde\source\repos\mybot\commands\testing\deleteMessages.js:5:10)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
constraint: 's.string.regex',
given: 'DeleteMessages',
expected: 'expected /^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}_-]+$/u.test(expected) to be true'
}
d.js docs
d.js docs17mo ago
guide Slash Commands: Option types Integer only accepts whole numbers. read more
Syjalo
Syjalo17mo ago
Names should be in lower case
ig
igOP17mo ago
Okay thank you
Want results from more Discord servers?
Add your server