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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With