feat(GuildMember): set theme colors

This commit is contained in:
March 7th 2022-10-26 22:34:09 +07:00
parent 0c3d922096
commit 31e0de6a05
5 changed files with 33 additions and 1 deletions

View File

@ -9,6 +9,7 @@ module.exports = (client, packet) => {
*/ */
const channel = client.channels.cache.get(packet.d.channel_id); const channel = client.channels.cache.get(packet.d.channel_id);
if (!channel) return; if (!channel) return;
if (!channel._recipients) channel._recipients = [];
channel._recipients.push(packet.d.user); channel._recipients.push(packet.d.user);
const user = client.users._add(packet.d.user); const user = client.users._add(packet.d.user);
client.emit(Events.CHANNEL_RECIPIENT_ADD, channel, user); client.emit(Events.CHANNEL_RECIPIENT_ADD, channel, user);

View File

@ -9,6 +9,7 @@ module.exports = (client, packet) => {
*/ */
const channel = client.channels.cache.get(packet.d.channel_id); const channel = client.channels.cache.get(packet.d.channel_id);
if (!channel) return; if (!channel) return;
if (!channel._recipients) channel._recipients = [];
channel._recipients = channel._recipients.filter(r => r !== packet.d.user.id); channel._recipients = channel._recipients.filter(r => r !== packet.d.user.id);
const user = client.users._add(packet.d.user); const user = client.users._add(packet.d.user);
client.emit(Events.CHANNEL_RECIPIENT_REMOVE, channel, user); client.emit(Events.CHANNEL_RECIPIENT_REMOVE, channel, user);

View File

@ -7,6 +7,7 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors'); const { Error } = require('../errors');
const GuildMemberRoleManager = require('../managers/GuildMemberRoleManager'); const GuildMemberRoleManager = require('../managers/GuildMemberRoleManager');
const Permissions = require('../util/Permissions'); const Permissions = require('../util/Permissions');
const Util = require('../util/Util');
/** /**
* @type {WeakSet<GuildMember>} * @type {WeakSet<GuildMember>}
@ -452,6 +453,34 @@ class GuildMember extends Base {
return this.edit({ bio }); 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<GuildMember>}
*/
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. * Creates a DM channel between the client and this member.
* @param {boolean} [force=false] Whether to skip the cache check and request the API * @param {boolean} [force=false] Whether to skip the cache check and request the API

View File

@ -96,7 +96,7 @@ class PartialGroupDMChannel extends Channel {
*/ */
_patch(data) { _patch(data) {
super._patch(data); super._patch(data);
if ('recipients' in data) { if ('recipients' in data && Array.isArray(data.recipients)) {
this._recipients = data.recipients; this._recipients = data.recipients;
} }
if ('last_pin_timestamp' in data) { if ('last_pin_timestamp' in data) {

1
typings/index.d.ts vendored
View File

@ -1517,6 +1517,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
public toJSON(): unknown; public toJSON(): unknown;
public toString(): MemberMention; public toString(): MemberMention;
public valueOf(): string; public valueOf(): string;
public setThemeColors(primary?: ColorResolvable, accent?: ColorResolvable): GuildMember;
} }
export class GuildPreview extends Base { export class GuildPreview extends Base {