Если я создаю новое экспресс-приглашение на сервер, когда бот включен, возникает ошибка. В остальных случаях работает
const invites = {};
const wait = require('util').promisify(setTimeout);
client.on('ready', () => {
wait(1000);
g.fetchInvites().then(guildInvites => {
invites[g.id] = guildInvites;
});
});
});
client.on('guildMemberAdd', member => {
member.guild.fetchInvites().then(guildInvites => {
const ei = invites[member.guild.id];
invites[member.guild.id] = guildInvites;
const invite = guildInvites.find(i => ei.get(i.code).uses < i.uses);
const inviter = client.users.get(invite.inviter.id);
const logChannel = member.guild.channels.find(channel => channel.name === "join-logs");
logChannel.send(`${member.user.tag} joined using invite code ${invite.code} from ${inviter.tag}. Invite was used ${invite.uses} times since its creation.`);
});
});
Ошибка:
2019-07-07T09:49:20.363359+00:00 app[worker.1]: Unhandled Rejection:
2019-07-07T09:49:20.363377+00:00 app[worker.1]: TypeError: Cannot read property 'uses' of undefined
2019-07-07T09:49:20.363378+00:00 app[worker.1]: at guildInvites.find.i (./bot.js:398:57)
2019-07-07T09:49:20.363380+00:00 app[worker.1]: at Map.find (./node_modules/discord.js/src/util/Collection.js:160:13)
2019-07-07T09:49:20.363381+00:00 app[worker.1]: at member.guild.fetchInvites.then.guildInvites (./bot.js:398:33)
2019-07-07T09:49:20.363382+00:00 app[worker.1]: at process._tickCallback (internal/process/next_tick.js:68:7)
398 срок
const invite = guildInvites.find(i => ei.get(i.code).uses < i.uses);