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

187
Vistas
Fetching a guild using its ID returns every available guild in discord.js

I am trying to fetch a guild using its ID which the bot is in, but it doesn't seem to work. Whenever I run this, it outputs a collection of every guild the client is in.

e is read from a JSON file, the id property is a direct copy from the server.

client.guilds.fetch(e.id).then((guild) => {
  // logs every available guild instead of the one where id is e.id
  console.log(guild)
})

Here are my intents and partials

const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.DIRECT_MESSAGES, 
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS, 
    Intents.FLAGS.DIRECT_MESSAGE_REACTIONS
  ],
  partials: ['MESSAGE', 'CHANNEL', 'REACTION'], 
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are two options; either your id is undefined or it's a number.

As fetch only accepts a GuildResolvable, or a FetchGuildOptions/FetchGuildsOptions object as its parameter. If you pass something else, it's just ignored and every available guild gets fetched (just like you mentioned).

I think your id is a snowflake, as you mentioned that it's coming from a JSON file. Snowflakes should always be strings. If you store these IDs as numbers, JS has difficulty interpreting them. Any number greater than the MAX_SAFE_INTEGER becomes a different number, and if you provide a different ID, again, every available guild gets fetched.

For example, if your snowflake is 921423246421811231, it becomes 921423246421811200. Try to run the snippet below, you'll see that it logs the second number, not what the value of e.id:

let e = {
  id: 921423246421811231
}

console.log(e.id)

To solve this, make sure you store the id as a string in your JSON file:

{
  "id": "921423246421811231"
}
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