Reputation: 331
So I want to make an invite to every server bot is inside.
The bot needs "CREATE_INSTANT_INVITE"
permission within the channel.
I made something like this but it seems not to work.
client.guilds.cache.forEach(guild => {
guild.channels.cache.first().createInvite()
.then(inv => console.log(`${guild.name} | ${inv.url}`));
});
Error:
DiscordAPIError: Unknown Channel
I think I get the error because bot tries to make an invite but he does not have permission to do so.
Upvotes: 1
Views: 786
Reputation: 786
Good afternoon,
The first()
channel is probably a category. You're not able to make invites on categories :sob: however, you could filter the guild's channels so that categories are not included.
Then you need to get a random()
channel and log that.
client.guilds.cache.forEach(guild => {
guild.channels.cache.filter(x => x.type != "category").random().createInvite()
.then(inv => console.log(`${guild.name} | ${inv.url}`));
});
The rest of your code was fine and should work as expected.
I hope this helps, don't forget to upvote the answer and mark it with a tick if it works.
Upvotes: 1