mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
Fixed ClientUser#createGroupDM on user accounts and added some more GroupDMChannel stuff (#1747)
* ClientUser#createGroupDM now works like the docs states on user accounts * Added GroupDMChannel#setIcon and fixed null handling for the channel name * Added an s * Don't resolve when icon is falsy and removed useless name trimming * Removed now unnecessary name constant * vscode being great * Added GroupDMChannel#iconURL
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const Channel = require('./Channel');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const Collection = require('../util/Collection');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
/*
|
||||
{ type: 3,
|
||||
@@ -103,6 +104,18 @@ class GroupDMChannel extends Channel {
|
||||
return this.client.users.get(this.ownerID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL to this Group DM's icon
|
||||
* @param {Object} [options={}] Options for the icon url
|
||||
* @param {string} [options.format='webp'] One of `webp`, `png`, `jpg`
|
||||
* @param {number} [options.size=128] One of `128`, '256', `512`, `1024`, `2048`
|
||||
* @returns {?string}
|
||||
*/
|
||||
iconURL({ format, size } = {}) {
|
||||
if (!this.icon) return null;
|
||||
return Constants.Endpoints.CDN(this.client.options.http.cdn).GDMIcon(this.id, this.icon, format, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this channel equals another channel. It compares all properties, so for most operations
|
||||
* it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often
|
||||
@@ -133,12 +146,29 @@ class GroupDMChannel extends Channel {
|
||||
edit(data, reason) {
|
||||
return this.client.api.channels[this.id].patch({
|
||||
data: {
|
||||
name: (data.name || this.name).trim(),
|
||||
icon: data.icon,
|
||||
name: data.name === null ? null : data.name || this.name,
|
||||
},
|
||||
reason,
|
||||
}).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new icon for this Group DM.
|
||||
* @param {Base64Resolvable} icon The new icon of this Group DM
|
||||
* @returns {Promise<GroupDMChannel>}
|
||||
*/
|
||||
setIcon(icon) {
|
||||
if (typeof icon === 'string' && icon.startsWith('data:')) {
|
||||
return this.edit({ icon });
|
||||
} else if (!icon) {
|
||||
return this.edit({ icon: null });
|
||||
} else {
|
||||
return this.client.resolver.resolveBuffer(icon)
|
||||
.then(data => this.edit({ icon: this.client.resolver.resolveBase64(data) }));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new name for this Group DM.
|
||||
* @param {string} name New name for this Group DM
|
||||
|
||||
Reference in New Issue
Block a user