getInteger('amount')
can someone help me, why this doesn't works?
ty
module.exports = {
data: new SlashCommandBuilder()
.setName('clear')
.setDescription('Cancella una quantità di messaggi')
.addIntegerOption(option => option.setName('amount').setDescription('Quantità di messaggi da eliminare').setMinValue(1).setMaxValue(20).setRequired(true)),
async execute(interaction) {
if (!interaction.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) {
return interaction.reply({ content: "Non hai il permesso di cancellare i messaggi!", ephemeral: true });
}
let number = interaction.options.getInteger('amount');
const embed = new EmbedBuilder()
.setColor("Blue")
.setDescription(
:white_check_mark: Cancellati ${number} messaggi
);
await interaction.channel.bulkDelete(number);
const button = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('cancella')
.setEmoji('🗑')
.setStyle(ButtonStyle.PRIMARY)
);
const message = await interaction.reply({ embeds: [embed], components: [button] });
const collector = message.createMessageComponentCollector();
collector.on("collect", async i => {
if (i.customId === 'cancella') {
if (!i.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) return;
interaction.deleteReply();
}
});
}
};17 Replies
- 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 OPIt's not this slash. Make sure you have created it and also restart your discord client
that's it...and I tried restarting my client several times
when you are deploying your commands, log the command and inspect the log
see if the options are there
I was thinking about it though, but I don't know, should I put an error for each part?
Have I made any progress? xd
module.exports = {
data: new SlashCommandBuilder()
.setName('clear')
.setDescription('Cancella una quantità di messaggi')
.addIntegerOption(option =>
option.setName('amount')
.setDescription('Numero di messaggi da cancellare')
.setRequired(true)),
async execute(interaction) {
if (!interaction.member.permissions.has(PermissionsBitField.Flags.ManageMessagesS)) {
return interaction.reply({ content: "Non hai il permesso di cancellare i messaggi!", ephemeral: true });
}
const amount = interaction.options.getInteger('amount');
if (amount < 1 || amount > 20) {
return interaction.reply({ content: 'Specifica un numero compreso tra 1 e 20 di messaggi da cancellare.', ephemeral: true });
}
try {
await interaction.channel.bulkDelete(amount + 1);
return interaction.reply({ content: Cancellati ${amount} messaggi., ephemeral: true });
} catch (error) {
console.error(error);
return interaction.reply({ content: 'Si è verificato un errore durante la cancellazione dei messaggi.', ephemeral: true });
}
},
};
nope
ok, i'd resolved
but now i've this other "problem"
nope
this is different
this is different
uhm
then no
in this code you create a command and a response to it, but you still need to handle it
maybe I understood
like that?
It doesn't look very good, but technically it is