I want to know how to make it so every guild the bot is in, it will make an invite and put it in console. It keeps giving me all these ANNOYING typerrors.
TypeError: Cannot read property 'first' of undefined
I tried changing and messing with the variables.
doopliss.on('ready', guild => {
doopliss.guilds.channels.first().createInvite()
.then(invite => console.log(invite.url))
.catch(err => console.error());
});
expect : bot that makes invites for every server it is in and posts it in console actual result : bot dies and gives off annoying typeerrors
You can use a forEach()
loop to get all the guild invites. For example...
doopliss.guilds.forEach(guild => {
guild.channels.first().createInvite()
.then(inv => console.log(`${guild.name} | ${inv.url}`));
// Outputs the guild name + the invite URL
});
See Map.forEach()
.