Created
August 1, 2017 23:09
-
-
Save codyphobe/07be96e9a8142669d99cfb035d8d16ed to your computer and use it in GitHub Desktop.
Deleting every message from a channel using DiscordJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = new Discord.Client(); | |
client.on('message', msg => { | |
let deleteStuff = () => { | |
let count = 0; | |
msg.channel.fetchMessages({limit: 100}) | |
.then(messages => { | |
let messagesArr = messages.array(); | |
let messageCount = messagesArr.length; | |
for(let i = 0; i < messageCount; i++) { | |
messagesArr[i].delete() | |
.then(function() { | |
count = count + 1; | |
if(count >= 100) { | |
deleteStuff(); | |
} | |
}) | |
.catch(function() { | |
count = count + 1; | |
if(count >= 100) { | |
deleteStuff(); | |
} | |
}) | |
} | |
}) | |
.catch(function(err) { | |
console.log('error thrown'); | |
console.log(err); | |
}); | |
}; | |
if(messageContent === '!:cleanse') { | |
deleteStuff(); | |
} | |
}; | |
client.login(process.env.TOKEN); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment