Estoy tratando de implementar un comando para eliminar los N últimos mensajes del bot en un canal. El bot no tiene permiso MANAGE_MESSAGES . Cuando N = 1, el bot elimina su último mensaje, según lo previsto. Sin embargo, cuando N > 1, el bot arroja el 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 } Lo que me resulta extraño es que, ¿cómo es que el bot puede eliminar 1 de sus mensajes, pero no más? Cuando probé el mismo código con MANAGE_MESSAGES habilitado, funciona perfectamente. ¿Es posible implementar esta funcionalidad sin el permiso MANAGE_MESSAGES , ya que solo quiero que el bot elimine sus propios mensajes, no los de otros?
Aquí está mi implementación:
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); }); }