diff --git a/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js b/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js index 443c31a..fc46539 100644 --- a/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +++ b/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js @@ -9,6 +9,7 @@ module.exports = (client, packet) => { */ const channel = client.channels.cache.get(packet.d.channel_id); if (!channel) return; + if (!channel._recipients) channel._recipients = []; channel._recipients.push(packet.d.user); const user = client.users._add(packet.d.user); client.emit(Events.CHANNEL_RECIPIENT_ADD, channel, user); diff --git a/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js b/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js index 6ba821c..5a2c917 100644 --- a/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +++ b/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js @@ -9,6 +9,7 @@ module.exports = (client, packet) => { */ const channel = client.channels.cache.get(packet.d.channel_id); if (!channel) return; + if (!channel._recipients) channel._recipients = []; channel._recipients = channel._recipients.filter(r => r !== packet.d.user.id); const user = client.users._add(packet.d.user); client.emit(Events.CHANNEL_RECIPIENT_REMOVE, channel, user); diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index c489550..45a6445 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -7,6 +7,7 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel'); const { Error } = require('../errors'); const GuildMemberRoleManager = require('../managers/GuildMemberRoleManager'); const Permissions = require('../util/Permissions'); +const Util = require('../util/Util'); /** * @type {WeakSet} @@ -452,6 +453,34 @@ class GuildMember extends Base { return this.edit({ bio }); } + /** + * Change Theme color + * @param {ColorResolvable} primary The primary color of the user's profile + * @param {ColorResolvable} accent The accent color of the user's profile + * @returns {Promise} + */ + async setThemeColors(primary, accent) { + if (this.user.id !== this.client.user.id) { + throw new Error('ONLY_ME'); + } + if (!primary || !accent) throw new Error('PRIMARY_COLOR or ACCENT_COLOR are required.'); + // Check nitro + if (this.nitroType !== 'NITRO_BOOST') { + throw new Error('NITRO_BOOST_REQUIRED', 'themeColors'); + } + primary = Util.resolveColor(primary) || this.themeColors ? this.themeColors[0] : 0; + accent = Util.resolveColor(accent) || this.themeColors ? this.themeColors[1] : 0; + const data_ = await this.client.api.guilds[this.guild.id].profile['@me'].patch({ + data: { + theme_colors: [primary, accent], + }, + }); + this._ProfilePatch({ + guild_member_profile: data_, + }); + return this; + } + /** * Creates a DM channel between the client and this member. * @param {boolean} [force=false] Whether to skip the cache check and request the API diff --git a/src/structures/PartialGroupDMChannel.js b/src/structures/PartialGroupDMChannel.js index d09299a..ba5c45a 100644 --- a/src/structures/PartialGroupDMChannel.js +++ b/src/structures/PartialGroupDMChannel.js @@ -96,7 +96,7 @@ class PartialGroupDMChannel extends Channel { */ _patch(data) { super._patch(data); - if ('recipients' in data) { + if ('recipients' in data && Array.isArray(data.recipients)) { this._recipients = data.recipients; } if ('last_pin_timestamp' in data) { diff --git a/typings/index.d.ts b/typings/index.d.ts index 0e95996..fabe447 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1517,6 +1517,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) { public toJSON(): unknown; public toString(): MemberMention; public valueOf(): string; + public setThemeColors(primary?: ColorResolvable, accent?: ColorResolvable): GuildMember; } export class GuildPreview extends Base {