Skip to content
Advertisement

Empty all channels with bulkDelete

I can’t seem to empty all my channels of their messages …

Here is my code:

message.guild.channels.cache.forEach(c => (c.bulkDelete(100));
            return message.reply(`A maximum of 100 messages were deleted in each channel.`);

Do you have any idea to solve my problem?

Solution :

message.guild.channels.cache.forEach(c => {
    if (c.isText()) {
        c.bulkDelete(100);
    }
});

Thank you

Advertisement

Answer

client doesn’t have a guild property. This returns undefined which then gives you that error. Perhaps you meant message.guild? message would be any Discord.Message, either from a parameter, fetched from channel, or even the value of a resolved promise (usually with .send()). So all you gotta do is change it from client.guild to message.guild.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement