gateway/events/guildmemberadd.js

  1. "use strict";
  2. // models
  3. const User = require('../../models/User');
  4. const Member = require('../../models/Member');
  5. /**
  6. * Emits once a user joins a guild
  7. * @event Client.GUILD_MEMBER_ADD
  8. * @prop {Member} member The member object that joined
  9. * @prop {Guild} guild The guild the member joined
  10. */
  11. class GuildMemberAdd {
  12. constructor() {}
  13. emit(shard, packet) {
  14. if (!packet.d.guild_id) return shard.client.emit('error', new Error('NEW MEMBER ON GUILD BUT NO GUILD FOUND!'));
  15. if (!shard.client.users.has(packet.d.user.id)) {
  16. shard.client.users.set(packet.d.user.id, new User(shard.client, packet.d.user));
  17. };
  18. let guild = shard.client.guilds.get(packet.d.guild_id);
  19. guild.memberCount++;
  20. packet.d.guild = guild;
  21. let member = guild.members.set(packet.d.user.id, new Member(shard.client, packet.d));
  22. shard.client.guilds.set(guild.id, guild);
  23. shard.client.emit('GUILD_MEMBER_ADD', member, guild);
  24. }
  25. };
  26. module.exports = GuildMemberAdd;