i've been trying to do a invites Command which should find all Invites from the Servers my Bot is on.
(ONLY MY OWN SERVERS)
I do have tried some ideas and code but nothing worked, how to implement it into my Discord Embed i do already know i just need help with the Invite Listing.
client.guilds.forEach(guild => {
guild.fetchInvites().then(guildInvites => {
invites[invites.length + 1] = (guild + " - `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);
}
})
});```
Help is much appreciated.
Are you caching your servers before fetching them? The cache is necessary so the bot can get information from each guild that it is in. Change the first line to
client.guilds.cache.forEach(() => {
// ...
}
Got this code from this answer here.
From the previous answers and comments on them, I can guess that you either don't have the required intents when instantiating the client class, OR that maybe your client class is not correctly defined.
How do you define client? If it's from another file, try importing it correctly. Don't make multiple clients from a same token/process.
client.guilds.cache.map(guild => {
let embed = new Discord.RichEmbed()
.setTitle("All Invites:")
guild.channels.cache
.first()
.createInvite()
.then((invite) => embed.setDescription(invites.url);)
.catch(() => embed.setDescription("Lien d'invitation", "Permission Invalides"));
message.channel.send(embed);
})