0

I have one question. How do I kick a user in every server that the bot and the user is in? I already tried it by myself, but it doesn't work.

bot.guilds.cache.map(SusUser.kick())
Kuezy
  • 101
  • 1
  • 2
  • 10

1 Answers1

2

This should work:

// https://stackoverflow.com/a/39914235/12101554
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// end copy

for (const guild of bot.guilds.cache) {
  const susGuildUser = await guild.members.fetch(SusUser);
  if (susGuildUser) {
    susGuildUser.kick();
    await sleep(200); // To prevent rate limiting, sleep 200ms between each kick (don't wait if user not in guild)
  }
}

This loops through all the guilds in the cache, looks for SusUser (i'm assuming this is a User object, which would automatically cast to UserResolvable), and if it exists (if they're in that server), kick them.

Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
  • May I ask you how to ban the user that way, but ban the user slowly. I don't want my bot to get rate limited. – Kuezy Aug 09 '21 at 17:48
  • @Kuezy I have updated my answer to include sleeping 200ms between each kick. The sleep function should be a global function, and make sure the `for` loop is inside an `async` function (if it's not, just wrap it in an `async` IIFE) – Samathingamajig Aug 09 '21 at 21:35