Unbanning all members

Hello, i want my bot to unban all banned people from the server, how can i do it?
23 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Frosty
FrostyOP3y ago
I have this code atm:
interaction.guild.fetchBans().then(banned => {

const bannedMembers = banned.map(user => user.tag).join('\n');
console.log(bannedMembers);
})
interaction.guild.fetchBans().then(banned => {

const bannedMembers = banned.map(user => user.tag).join('\n');
console.log(bannedMembers);
})
but i get this error: TypeError: interaction.guild.fetchBans is not a function
SpecialSauce
SpecialSauce3y ago
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Frosty
FrostyOP3y ago
Okay my code is this now:
interaction.guild.bans.fetch().then(banned => {

const bannedMembers = banned.map(user => user.tag).join('\n');
interaction.reply({ content: `${bannedMembers}`})
})
interaction.guild.bans.fetch().then(banned => {

const bannedMembers = banned.map(user => user.tag).join('\n');
interaction.reply({ content: `${bannedMembers}`})
})
But i get DiscordAPIError: Cannot send an empty message
Noxxe
Noxxe3y ago
You may hit a rate limit so just be careful when doing so!
Frosty
FrostyOP3y ago
But i do have people banned. Ye ik
Noxxe
Noxxe3y ago
Okie dokie, just to be on the safe side!
Frosty
FrostyOP3y ago
I have 3 people banned so should be fine atm. But for some reason it doesn't get the list of abnned people
Noxxe
Noxxe3y ago
Which DJS version are you using?
Frosty
FrostyOP3y ago
13.9
SpecialSauce
SpecialSauce3y ago
Bans has a cache
Noxxe
Noxxe3y ago
Just gonna say that lol try interaction.guild.bans.cache
SpecialSauce
SpecialSauce3y ago
The promise returns a collection of guildBans Not users directly
SpecialSauce
SpecialSauce3y ago
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Frosty
FrostyOP3y ago
I should do .....cache.fetch().then......... right?
SpecialSauce
SpecialSauce3y ago
You still can
Frosty
FrostyOP3y ago
interaction.guild.bans.cache.fetch().then(banned => {

const bannedMembers = banned.map(user => user.tag).join('\n');
interaction.reply({ content: `${bannedMembers}`})
})
interaction.guild.bans.cache.fetch().then(banned => {

const bannedMembers = banned.map(user => user.tag).join('\n');
interaction.reply({ content: `${bannedMembers}`})
})
like this.
SpecialSauce
SpecialSauce3y ago
bannedMembers is a Collection of GuildBans So you have to map the guild bans to user tags You’re veryyy close
Frosty
FrostyOP3y ago
And now i gotta make a foreach thing that unbans them?
SpecialSauce
SpecialSauce3y ago
That should be it
Noxxe
Noxxe3y ago
Just make sure to include a wait function of whatever you seen fit.
Frosty
FrostyOP3y ago
interaction.guild.bans.fetch().then(bans => {
bans.forEach(user => {
interaction.guild.bans.remove(user.user.id).then(user => interaction.reply({ content: `Unbanned | ${user.username}`}));
})
interaction.guild.bans.fetch().then(bans => {
bans.forEach(user => {
interaction.guild.bans.remove(user.user.id).then(user => interaction.reply({ content: `Unbanned | ${user.username}`}));
})
this works as well, more simple xd
SpecialSauce
SpecialSauce3y ago
user.user.id 🤢 I would rename user to guildBan But up to you 👍🏻
Want results from more Discord servers?
Add your server