// I don't even see my bot appearing (only the built-in stuff). import { Command } from '@sapphire/framework';
export class ClearCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'clear',
description: 'Supprime les derniers messages du salon actuel',
aliases: ['purge'],
preconditions: ['AdminOnly'],
idHints: ['1306666895696593017']
});
}
registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.addIntegerOption((option) =>
option
.setName('nombre')
.setDescription('Nombre de message à supprimer')
.setRequired(true)
)
);
}
chatInputRun(interaction) {
const channel = interaction.channel;
const messagesToDelete = interaction.options.getInteger('nombre');
if (messagesToDelete > 100) {
return interaction.reply({
content: 'Vous ne pouvez pas supprimer plus de 100 messages à la fois',
ephemeral: true,
});
}
return channel.bulkDelete(messagesToDelete)
.then(() => {
interaction.reply({
content: `Messages supprimés avec succès`,
ephemeral: true,
});
})
}
}import { Command } from '@sapphire/framework';
export class ClearCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'clear',
description: 'Supprime les derniers messages du salon actuel',
aliases: ['purge'],
preconditions: ['AdminOnly'],
idHints: ['1306666895696593017']
});
}
registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
.addIntegerOption((option) =>
option
.setName('nombre')
.setDescription('Nombre de message à supprimer')
.setRequired(true)
)
);
}
chatInputRun(interaction) {
const channel = interaction.channel;
const messagesToDelete = interaction.options.getInteger('nombre');
if (messagesToDelete > 100) {
return interaction.reply({
content: 'Vous ne pouvez pas supprimer plus de 100 messages à la fois',
ephemeral: true,
});
}
return channel.bulkDelete(messagesToDelete)
.then(() => {
interaction.reply({
content: `Messages supprimés avec succès`,
ephemeral: true,
});
})
}
}[DEBUG] ApplicationCommandRegistry[clear] Preparing to process 1 possible command registrations / updates...
[DEBUG] ApplicationCommandRegistry[clear] Checking if command "clear" is identical with global chat input command with id "1306666895696593017"
[DEBUG] ApplicationCommandRegistry[clear] Registering id "1306666895696593017" to internal chat input map
[DEBUG] ApplicationCommandRegistry[clear] Took 1ms to process differences via fast compute differences
[DEBUG] ApplicationCommandRegistry[clear] Found differences for command "clear" (1306666895696593017) versus provided api data.
[DEBUG] ApplicationCommandRegistry[clear] Updated command clear (1306666895696593017) with new api data
[INFO] ApplicationCommandRegistries: Took 251ms to initialize.[DEBUG] ApplicationCommandRegistry[clear] Preparing to process 1 possible command registrations / updates...
[DEBUG] ApplicationCommandRegistry[clear] Checking if command "clear" is identical with global chat input command with id "1306666895696593017"
[DEBUG] ApplicationCommandRegistry[clear] Registering id "1306666895696593017" to internal chat input map
[DEBUG] ApplicationCommandRegistry[clear] Took 1ms to process differences via fast compute differences
[DEBUG] ApplicationCommandRegistry[clear] Found differences for command "clear" (1306666895696593017) versus provided api data.
[DEBUG] ApplicationCommandRegistry[clear] Updated command clear (1306666895696593017) with new api data
[INFO] ApplicationCommandRegistries: Took 251ms to initialize.async chatInputRun(interaction) {
try {
const messagesToDelete = interaction.options.getInteger('nombre');
// Validate the number of messages to delete
if (messagesToDelete < 1 || messagesToDelete > 100) {
return interaction.reply({
content: 'Veuillez spécifier un nombre entre 1 et 100.',
ephemeral: true
});
}
// Check if the interaction is in a guild
if (!interaction.guild) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un serveur.',
ephemeral: true
});
}
// Ensure the channel is a text-based channel
const channel = interaction.channel;
if (!channel || !channel.isTextBased()) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un salon texte.',
ephemeral: true
});
}
// Check if the bot has the required permissions
const botMember = interaction.guild.members.me;
if (!botMember.permissionsIn(channel).has(PermissionsBitField.Flags.ManageMessages)) {
return interaction.reply({
content: 'Je n\'ai pas la permission de supprimer des messages dans ce salon.',
ephemeral: true
});
}
await interaction.deferReply({ ephemeral: true });
// Fetch messages and filter out messages older than 14 days
const fetchedMessages = await channel.messages.fetch({ limit: messagesToDelete });
const messagesToBulkDelete = fetchedMessages.filter(
(msg) => Date.now() - msg.createdTimestamp < 14 * 24 * 60 * 60 * 1000
);
if (messagesToBulkDelete.size === 0) {
return interaction.editReply({
content: 'Aucun message récent à supprimer.',
});
}
// Bulk delete messages
const deletedMessages = await channel.bulkDelete(messagesToBulkDelete, true);
await interaction.editReply({
content: `${deletedMessages.size} messages ont été supprimés.`,
});
} catch (error) {
this.container.logger.error('Error in PurgeCommand:', error);
if (interaction.deferred || interaction.replied) {
await interaction.editReply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
});
} else {
await interaction.reply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
ephemeral: true
});
}
}
}async chatInputRun(interaction) {
try {
const messagesToDelete = interaction.options.getInteger('nombre');
// Validate the number of messages to delete
if (messagesToDelete < 1 || messagesToDelete > 100) {
return interaction.reply({
content: 'Veuillez spécifier un nombre entre 1 et 100.',
ephemeral: true
});
}
// Check if the interaction is in a guild
if (!interaction.guild) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un serveur.',
ephemeral: true
});
}
// Ensure the channel is a text-based channel
const channel = interaction.channel;
if (!channel || !channel.isTextBased()) {
return interaction.reply({
content: 'Cette commande ne peut être utilisée que dans un salon texte.',
ephemeral: true
});
}
// Check if the bot has the required permissions
const botMember = interaction.guild.members.me;
if (!botMember.permissionsIn(channel).has(PermissionsBitField.Flags.ManageMessages)) {
return interaction.reply({
content: 'Je n\'ai pas la permission de supprimer des messages dans ce salon.',
ephemeral: true
});
}
await interaction.deferReply({ ephemeral: true });
// Fetch messages and filter out messages older than 14 days
const fetchedMessages = await channel.messages.fetch({ limit: messagesToDelete });
const messagesToBulkDelete = fetchedMessages.filter(
(msg) => Date.now() - msg.createdTimestamp < 14 * 24 * 60 * 60 * 1000
);
if (messagesToBulkDelete.size === 0) {
return interaction.editReply({
content: 'Aucun message récent à supprimer.',
});
}
// Bulk delete messages
const deletedMessages = await channel.bulkDelete(messagesToBulkDelete, true);
await interaction.editReply({
content: `${deletedMessages.size} messages ont été supprimés.`,
});
} catch (error) {
this.container.logger.error('Error in PurgeCommand:', error);
if (interaction.deferred || interaction.replied) {
await interaction.editReply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
});
} else {
await interaction.reply({
content: 'Une erreur s\'est produite lors de la suppression des messages.',
ephemeral: true
});
}
}
}