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

241
Views
¿Cómo obtener más de 1000 prohibiciones de un servidor de discordia usando discord.js?

Tengo un comando serverinfo y muestra cuántas prohibiciones hay en el servidor. Si el servidor tiene 1200 bloqueos, el bot mostrará que el servidor tiene 1000 bloqueos.

¿Es posible hacer que el bot muestre de alguna manera cuántas prohibiciones son realmente?

En la documentación se especifican los siguientes parámetros limit?| number | number of users to return (up to maximum 1000) | default 1000

¿Cómo cambiar el valor predeterminado de 1000 a, por ejemplo, 1500?

Estoy usando discord.js versión 13.8.0 y node.js versión 16.15.1.

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

0

Aunque el límite máximo es 1000, también puede usar el limit y before de las opciones para obtener las prohibiciones anteriores. before es un copo de nieve, le dice a Discord que considere solo prohibiciones antes de esta identificación.

Por lo tanto, si tiene alrededor de 1200 bloqueos, puede obtener los primeros 1000, obtener la identificación del último elemento en la colección devuelta y usar su id como la opción before en su segunda recuperación:

 let firstHalf = await guild.bans.fetch({ limit: 1000 }); let secondHalf = await guild.bans.fetch({ before: firstHalf.last().id, limit: 1000 });

También puede crear una nueva función que obtenga más de 1000 prohibiciones. Hay un ejemplo a continuación. Esta función devuelve una collection de GuildBan s , por lo que puede usar los métodos de recolección habituales , como filter , each , etc.

 async function fetchMoreBans(guild, limit = 2000) { if (!guild || typeof guild !== 'object') throw new Error(`Expected a guild, got "${typeof guild}"`); if (!Number.isInteger(limit)) throw new Error(`Expected an integer, got ${typeof limit}.`); if (limit <= 1000) return guild.bans.fetch({ limit }); let collection = new Collection(); let lastId = null; let options = {}; let remaining = limit; while (remaining > 0) { options.limit = remaining > 1000 ? 1000 : remaining; remaining = remaining > 1000 ? remaining - 1000 : 0; if (lastId) options.before = lastId; let bans = await guild.bans.fetch(options); if (!bans.last()) break; collection = collection.concat(bans); lastId = bans.last().id; } return collection; }

Ejemplo de uso:

 client.on('messageCreate', async (message) => { if (message.author.bot) return; let banList = await fetchMore(message.guild, 1500); let filteredBanList = banList.filter(({ user }) => user.username.toLowerCase().startsWith('e'), ); console.log(`There are ${banList.size} bans fetched`); console.log( `Number of bans where the user's username starts with the letter "e": ${filteredBanList.size}`, ); });
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!