Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a user is banned or not?

I have managed to make the unban command to work, but now I need to make a condition to avoid errors, and need to put the unban code inside the condition if the user is in the ban list, but I have no idea how and haven't seen anything on internet.

like image 318
Mr Ochoa Avatar asked Sep 19 '25 08:09

Mr Ochoa


1 Answers

You can use Guild.fetchBans() to retrieve a Collection of banned users. Keep in mind, this method returns a Promise. You can then use Collection.find() to search through the Collection.

Example:

// Async context needed for 'await' (meaning this must be within an async function).
// Assuming 'message' is a Message within the guild.

try {
  const banList = await message.guild.fetchBans();

  const bannedUser = banList.find(user => user.id === 'someID');

  if (bannedUser) await message.channel.send(`${bannedUser.tag} is banned.`);
  else await message.channel.send('That user is not banned.');
} catch(err) {
  console.error(err);
}
like image 147
slothiful Avatar answered Sep 20 '25 22:09

slothiful