I have a bot in my Discord server for playing music. As it works with commands, and it answers if there is something like a playlist the channel is spammed with songs or messages that later on are meaningless. So I want the bot that each time it leaves a voice channel, it clears the command messages that were sent to it and the answer messages that it sent.
So I have looked around a bit and came to this code but it doesnt work. I added some console logs to see up where it goes in, and it reaches FLAG 1 but not FLAG 2. So what is wrong in that condition? PREFIX is the "!" that commands start with, and 0123456789 is the bot ID
else if (msg.content.trim().toLowerCase() == _CMD_LEAVE) {
const channel = msg.channel;
const messageManager = channel.messages;
messageManager.fetch({ limit: 100 }).then((messages) => {
messages.forEach((message) => {
console.log("FLAG 1: "+ util.inspect(message))
if ( (message.content.startWith(PREFIX)) || (message.author.id == 0123456789)) {
console.log("FLAG 2: "+ util.inspect(message))
message.delete();
}
});
});
}
Thanks in advance