'Ban all command not working for discord bot. (discord js)

I'm trying to make a ban all command for my bot and am having issues. When I try to use it, I get an error:

DiscordAPTError: Missing Permissions

This is my code:

const { Client, Discord } = require("discord.js")
module.exports.run = async (bot, message, args) => {
  try {
    message.guild.members.cache.each(m => {
      m.ban();
  });
  } catch(e) {
    console.log(e.stack);
  }
}

module.exports.help = {
  name: "banall",
  desc: "Bans everyone",
}


Solution 1:[1]

Use this:

let members = await message.guild.members.fetch();
members.forEach(member => {
    if (member.bannable) {
        member.ban().catch((err) => { console.log(err); });
    }
});

Also make sure your bot has the correct intents (configured in your js file) and permissions on the server (role perms)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P