Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Ban member from other guild if banned in main guild

So I want it where, if a user gets banned from this specified guild, it will ban them in every other guild that the bot is in. Do I use fetch bans to do this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Before we continue you need to make sure that you are requesting the following intents when creating your bot, as they are necessary to achieve your goal: GUILDS, GUILD_BANS.

const { Client, Intents } = require('discord.js');
const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_BANS]
});

You should also set up a constant called MAIN_GUILD_ID or something along those lines:

const MAIN_GUILD_ID = 'ID';

Now you need to listen to the guildBanAdd event and check if the GuildBan.guild#id equals the main Guild#id (making sure the user was banned in the main Guild).

client.on('guildBanAdd', async ban => {
    if (ban.guild.id !== MAIN_GUILD_ID) return;
});

Then you can loop through all of the Guilds your bot is in and ban the user there.

client.on('guildBanAdd', async ban => {
    if (ban.guild.id !== MAIN_GUILD_ID) return;

    // Getting the guilds from the cache and filtering the main guild out.
    const guilds = await client.guilds.cache.filter(guild => guild.id !== MAIN_GUILD_ID);

    guilds.forEach(guild => {
        guild.members.ban(ban.user, {
            reason: `${ban.user.tag} was banned from ${guild.name}.`
        }).then(() => {
            console.log(`Banned ${ban.user.tag} from ${guild.name}.`);
        }).catch(err => {
            console.error(`Failed to ban ${ban.user.tag} from ${guild.name}.`, err);
        });
    })
});

I'm assuming this is for a private bot that is in a few guilds, otherwise, if the bot is in a few hundred or more guilds it will get your application rate-limited pretty fast.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!