Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda