Files
TTtie 476fa65b0a chore: default the image format to .webp, add missing dynamic image methods (#257)
- Makes .webp the default image format for both static and animated
images
  - Discord documentation states that assets uploaded as animated
  .webp/.avif aren't converted to other formats. (see ref)
  - Although static .webp is still converted to other formats, using a
  single image format makes matters a bit more consistent
  - This is obviously a breaking change for users that expect to get a
  .jpg/.gif out of the URL getters. Most reasonably modern image
  processing toolkits should be able to take .webp media just fine though.
- .webp links will now contain the `?animated=true` query string
parameter for animated images
  - An additional boolean parameter has been added to `dynamic[...]URL()`
  APIs to exclude the parameter, forcing a static version of the image.
- Added some missing dynamic URL APIs, namely `Role#dynamicIconURL` and
`GuildScheduledEvent#dynamicImageURL`

Ref:
https://github.com/discord/discord-api-docs/commit/ab3ea3c8d7a7c5ddc6b991f409355b4fa86bc9b3
2026-07-29 23:34:49 +00:00

69 lines
1.9 KiB
JavaScript

"use strict";
const Endpoints = require("../rest/Endpoints");
const PrivateChannel = require("./PrivateChannel");
/**
* Represents a group channel
* @extends PrivateChannel
*/
class GroupChannel extends PrivateChannel { // (╯°□°)╯︵ ┻━┻
#client;
constructor(data, client) {
super(data, client);
this.#client = client;
if(data.name !== undefined) {
/**
* The name of this group channel
* @type {String}
*/
this.name = data.name;
}
if(data.owner_id !== undefined) {
/**
* The ID of the owner of this group channel
* @type {String}
*/
this.ownerID = data.owner_id;
}
if(data.icon !== undefined) {
/**
* The hash of the group channel icon
* @type {String?}
*/
this.icon = data.icon;
}
}
/**
* The URL of the group channel icon
* @type {String?}
*/
get iconURL() {
return this.icon ? this.#client._formatImage(Endpoints.CHANNEL_ICON(this.id, this.icon)) : null;
}
/**
* Get the group's icon with the given format and size
* @param {String} [format] The filetype of the icon ("jpg", "jpeg", "png", "gif", or "webp")
* @param {Number} [size] The size of the icon (any power of two between 16 and 4096)
* @param {Boolean} [forceStatic=false] Whether to force the icon to be static even if it is animated
* @returns {String?}
*/
dynamicIconURL(format, size, forceStatic) {
return this.icon ? this.#client._formatImage(Endpoints.CHANNEL_ICON(this.id, this.icon), format, size, forceStatic) : null;
}
toJSON(props = []) {
return super.toJSON([
"icon",
"name",
"ownerID",
...props
]);
}
}
module.exports = GroupChannel;