I'm trying to create a Discord bot that'll create an invite to the first channel of a Guild when it's added to the aforementioned guild and sending it to the console.
My code (it doesn't work):
client.on("guildCreate", guild => {
const channel = Array.from(guild.channels).sort((a, b) => a.calculatedPosition - b.calculatedPosition)[0];
channel.createInvite({
unique: true
})
.then(invite => {
console.log(`Joined to: ${guild.name} Invite: https://discord.gg/${invite.code}`);
})
});