Forked from Sv443/discord-js-get-all-guild-invites.js
Created
March 30, 2022 12:33
-
-
Save Gesugao-san/c9931088a558cbf2cb5007d2255cc259 to your computer and use it in GitHub Desktop.
Discord.js - Get all invites from all your bot's guilds - only works with Discord.js v11 or lower!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// only works with Discord.js v11 or lower! | |
const Discord = require("discord.js"); | |
const dev_ids = ["YOUR_ID(s)_HERE"]; // an array of IDs of the bot's developers - only these people will be able to execute this command | |
// Note: this snippet requires the variables "client" and "message" to work, these need to be provided by your script | |
var allowedToUse = false; | |
dev_ids.forEach(id => { | |
if(message.author.id == id) | |
allowedToUse = true; | |
}); | |
if(allowedToUse) { | |
let invites = ["ignore me"], ct = 0; | |
client.guilds.forEach(g => { | |
g.fetchInvites().then(guildInvites => { | |
invites[invites.length + 1] = (g + " - `Invites: " + guildInvites.array().join(", ") + "`"); | |
ct++; | |
if(ct >= client.guilds.size) { | |
invites.forEach((invite, i) => { | |
if(invite == undefined) | |
invites.splice(i, 1); | |
}); | |
invites.shift(); | |
invites.forEach((invite, i) => invites[i] = "- " + invite); | |
invites = invites.join("\n\n"); | |
let embed = new Discord.RichEmbed() | |
.setTitle("All Invites:") | |
.setDescription(invites); | |
message.channel.send(embed); | |
} | |
}).catch(err => { | |
ct++; | |
}); | |
}); | |
} | |
else { | |
message.reply("this command can only be used by a developer."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment