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

253
Visualizações
Missing Permissions when using bulkDelete() on the bot's own messages

I'm trying to implement a command to delete the bot's N last messages in a channel. The bot does not have MANAGE_MESSAGES permission. When N = 1, the bot deletes its latest message, as intended. However, when N > 1, the bot throw the error:

D:\Seneca\7th_Term\DPS909\EarTensifier\node_modules\discord.js\src\rest\RequestHandler.js:170
          return reject(new DiscordAPIError(request.path, data, request.method, res.status));
                        ^

DiscordAPIError: Missing Permissions
    at RequestHandler.execute (D:\Seneca\7th_Term\DPS909\EarTensifier\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {      
  method: 'post',
  path: '/channels/757408200973877277/messages/bulk-delete',
  code: 50013,
  httpStatus: 403
}

What is weird to me is that how come the bot be able to delete 1 of its message, but not more? When I tested the same code with MANAGE_MESSAGES enabled, it works perfectly. Is it possible to implement this functionality without the MANAGE_MESSAGES permission, since I only want the bot to delete its own messages, not others'?

Here is my implementation:

const botID = process.env.DISCORD_ID;
if (message.channel.type == 'text') {
    await message.channel.messages.fetch({limit: 100}).then(messages => {
        let botMessages = messages.filter(msg => msg.author == botID).array();
        if (no_of_messages > 0){
            botMessages.splice(no_of_messages);
        }
        message.channel.bulkDelete(botMessages);
        client.log(`Deleted ${botMessages.length} messages from ${botID}`)
    }).catch(err => {
        client.log('Error while doing Bulk Delete');
        client.log(err);
    });
}
about 4 years ago · Juan Pablo Isaza
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