Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda