Я бы настроил рекурсивную функцию, которая проверяет, есть ли в канале сообщения (максимум 100 каждый раз): если сообщений нет, они останавливаются, в противном случае они удаляются и перезапускаются.
function clean(channel, limit = 100) {
return channel.fetchMessages({limit}).then(async collected => {
let mine = collected.filter(m => m.author.id == 'your_id_here'); // this gets only your messages
if (mine.size > 0) {
await channel.bulkDelete(mine, true);
clean(channel);
} else channel.send("The channel is now empty!").delete(5000); // this message is deleted after 5 s
});
}
Выможете адаптировать эту идею к существующему парсеру команд или, если вы не знаете, как это реализовать, попробуйте:
client.on('message', msg => {
if (msg.author.bot || msg.author != YOU) return;
// with YOU i mean your User object, to check permissions
let command = 'clean', // the name of your command
args = msg.content.split(' ');
if (args[0].toLowerCase() == command)
clean(msg.channel, !isNaN(args[1]) ? args[1] : undefined); //<-- THIS is how to use the function
// used a ternary operator to check if the other arg is a number
});
Это просто очень базовая реализация, естьмного лучших способов обнаружения команд.