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 => role.name === 'Staff')) 
   return message.reply("You can't use this command.");
var targetID = args[1]; // this is the targets UserID

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


return;
}

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(!message.author === Owner) return message.channel.send("You need to be bot owner to use this command");
            
            else{
            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`)
            .setColor("#FF0000")
            .setThumbnail("https://cdn.discordapp.com/emojis/764396593964122132.gif?v=1")
            message.channel.send(embed)
    
            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](https://discord.gg/ZWWYy37atN)')
            .setColor("#FF0000")
            message.targetID.send(embed)
            }
        }
    }
    
    Reply
  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()

    Reply

Leave a Comment