GUILD_CREATE.js (1196B)
1 'use strict'; 2 3 const { Events, Status } = require('../../../util/Constants'); 4 5 module.exports = async (client, { d: data }, shard) => { 6 let guild = client.guilds.cache.get(data.id); 7 if (guild) { 8 if (!guild.available && !data.unavailable) { 9 // A newly available guild 10 guild._patch(data); 11 // If the client was ready before and we had unavailable guilds, fetch them 12 if (client.ws.status === Status.READY && client.options.fetchAllMembers) { 13 await guild.members 14 .fetch() 15 .catch(err => client.emit(Events.DEBUG, `Failed to fetch all members: ${err}\n${err.stack}`)); 16 } 17 } 18 } else { 19 // A new guild 20 data.shardID = shard.id; 21 guild = client.guilds.add(data); 22 if (client.ws.status === Status.READY) { 23 /** 24 * Emitted whenever the client joins a guild. 25 * @event Client#guildCreate 26 * @param {Guild} guild The created guild 27 */ 28 if (client.options.fetchAllMembers) { 29 await guild.members 30 .fetch() 31 .catch(err => client.emit(Events.DEBUG, `Failed to fetch all members: ${err}\n${err.stack}`)); 32 } 33 client.emit(Events.GUILD_CREATE, guild); 34 } 35 } 36 };