mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
ClientUserGuildSettings: avoid uncaught exception and a bit of refactoring (#1885)
* refactor(ClientUserGuildSettings): make client first parameter of the constructor * refactor(ClientUserChannelOverride): patch if possible rather then reinstantiating every update * fix(ClientUserGuildSettings): avoid uncaught exception when patching newly joined guilds/gdms
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
const Constants = require('../../../../util/Constants');
|
||||
const ClientUserGuildSettings = require('../../../../structures/ClientUserGuildSettings');
|
||||
|
||||
class UserGuildSettingsUpdateHandler extends AbstractHandler {
|
||||
handle(packet) {
|
||||
const client = this.packetManager.client;
|
||||
client.user.guildSettings.get(packet.d.guild_id).patch(packet.d);
|
||||
const settings = client.user.guildSettings.get(packet.d.guild_id);
|
||||
if (settings) settings.patch(packet.d);
|
||||
else client.user.guildSettings.set(packet.d.guild_id, new ClientUserGuildSettings(this.client, packet.d));
|
||||
client.emit(Constants.Events.USER_GUILD_SETTINGS_UPDATE, client.user.guildSettings.get(packet.d.guild_id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user