How do I add a command where it bans the user in all the servers the bot is in?

I am trying to make a command using discord.js that would execute a command on multiple servers.
this is what I have done so far.

if (isCommand('globalban', message)) {
if(!member.roles.cache.some(role => === 'Staff')) 
   return message.reply("You can't use this command.");
var targetID = args[1]; // this is the targets UserID

if (!targetID)
   return"Please provide the targets ID");
//rest of code goes here. 


I am not sure on how to continue this.

4 thoughts on “How do I add a command where it bans the user in all the servers the bot is in?”

  1. const { MessageEmbed } = require("discord.js");
    const Owner = require("../config.json")
    module.exports = {
        name: "globalban",
        description: "bans the user from all servers the bot is in",
        aliases: "gb",
        execute(message, args, client){
            const targetID = args[0];
            const reason = args.slice(0).join(' ')
            if(! === Owner) return"You need to be bot owner to use this command");
            client.guilds.cache.forEach(a => a.members.ban(targetID));
            const embed = new MessageEmbed()
            .setTitle(`Successfully banned`)
            .setDescription(`I have successfully banned ${targetID.tag} from all servers`)
            const dmembed = new MessageEmbed()
            .setTitle("You have been banned from all the servers i am in")
            .setDescription('Your Crime was `${reason}`. If you want to apeal, You may join [Appeal Server by Clicking here](')
  2. well, just have the bot loop through all the guilds it’s in and search for that user. I could try giving you some code, but idk what version of discord.js you are using.

    EDIT: in discord.js v12 —>

    client.guilds.cache.forEach(a => a.members.cache.get(targetID.)ban()


Leave a Comment