Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
Why is my purge command deleting all the messages in the chat and not the given number?

I am working on my bot for some time now, And I am working on a purge command. Only the problem is that the bot is deleting all the messages in the chat. Not the given number. Here is the code:

const { Permissions } = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const Discord = require('discord.js');

module.exports = {
    name: 'purge',
    description: 'Deletes a amount of messages in the chat.',
    admin: true,
    async execute(message, args){
        if (!message.member.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) return message.channel.send("You don't have the permissions to execute this command.");
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("Enter a valid amount between 2 and 100.");
        if(args[0] < 1) return message.reply("You entered a value below 0, enter a value above 0.");

        await message.channel.messages.fetch({limit: args[1]}).then(messages =>{
            message.channel.bulkDelete(messages, true)
        });

    
    }
} 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is the one that works properly!

const { Permissions } = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const Discord = require('discord.js');

module.exports = {
    name: 'purge',
    description: 'Deletes a amount of messages in the chat.',
    admin: true,
    async execute(message, args){
        if (!message.member.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) return message.channel.send("You don't have the permissions to execute this command.");
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("Enter a valid amount between 2 and 100.");
        if(args[0] < 1) return message.reply("You entered a value below 0, enter a value above 0.");

        await message.channel.messages.fetch({limit: args[0]}).then(messages =>{
            message.channel.bulkDelete(messages, true)
        });

    
    }
} 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda