mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: Support widget image URL (#9782)
* feat: add widget image URL * docs(GuildManager): correct parameter type Co-authored-by: space <spaceeec@yahoo.com> --------- Co-authored-by: space <spaceeec@yahoo.com>
This commit is contained in:
@@ -4,7 +4,7 @@ const process = require('node:process');
|
||||
const { setTimeout, clearTimeout } = require('node:timers');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { makeURLSearchParams } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v10');
|
||||
const { Routes, RouteBases } = require('discord-api-types/v10');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { Guild } = require('../structures/Guild');
|
||||
const GuildChannel = require('../structures/GuildChannel');
|
||||
@@ -278,6 +278,20 @@ class GuildManager extends CachedManager {
|
||||
const data = await this.client.rest.get(Routes.userGuilds(), { query: makeURLSearchParams(options) });
|
||||
return data.reduce((coll, guild) => coll.set(guild.id, new OAuth2Guild(this.client, guild)), new Collection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL for the PNG widget of a guild.
|
||||
* @param {GuildResolvable} guild The guild of the widget image
|
||||
* @param {GuildWidgetStyle} [style] The style for the widget image
|
||||
* @returns {string}
|
||||
*/
|
||||
widgetImageURL(guild, style) {
|
||||
const urlSearchParams = String(makeURLSearchParams({ style }));
|
||||
|
||||
return `${RouteBases.api}${Routes.guildWidgetImage(this.resolveId(guild))}${
|
||||
urlSearchParams ? `?${urlSearchParams}` : ''
|
||||
}`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildManager;
|
||||
|
||||
@@ -723,6 +723,15 @@ class Guild extends AnonymousGuild {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL for the PNG widget of the guild.
|
||||
* @param {GuildWidgetStyle} [style] The style for the widget image
|
||||
* @returns {string}
|
||||
*/
|
||||
widgetImageURL(style) {
|
||||
return this.client.guilds.widgetImageURL(this.id, style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options used to fetch audit logs.
|
||||
* @typedef {Object} GuildAuditLogsFetchOptions
|
||||
|
||||
@@ -83,6 +83,15 @@ class Widget extends Base {
|
||||
this._patch(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL for the PNG widget of the guild.
|
||||
* @param {GuildWidgetStyle} [style] The style for the widget image
|
||||
* @returns {string}
|
||||
*/
|
||||
imageURL(style) {
|
||||
return this.client.guilds.widgetImageURL(this.id, style);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Widget;
|
||||
|
||||
@@ -350,6 +350,11 @@
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/GuildVerificationLevel}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external GuildWidgetStyle
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/GuildWidgetStyle}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external IntegrationExpireBehavior
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/IntegrationExpireBehavior}
|
||||
|
||||
4
packages/discord.js/typings/index.d.ts
vendored
4
packages/discord.js/typings/index.d.ts
vendored
@@ -166,6 +166,7 @@ import {
|
||||
AttachmentFlags,
|
||||
RoleFlags,
|
||||
TeamMemberRole,
|
||||
GuildWidgetStyle,
|
||||
} from 'discord-api-types/v10';
|
||||
import { ChildProcess } from 'node:child_process';
|
||||
import { EventEmitter } from 'node:events';
|
||||
@@ -1384,6 +1385,7 @@ export class Guild extends AnonymousGuild {
|
||||
public fetchWelcomeScreen(): Promise<WelcomeScreen>;
|
||||
public fetchWidget(): Promise<Widget>;
|
||||
public fetchWidgetSettings(): Promise<GuildWidgetSettings>;
|
||||
public widgetImageURL(style?: GuildWidgetStyle): string;
|
||||
public leave(): Promise<Guild>;
|
||||
public disableInvites(disabled?: boolean): Promise<Guild>;
|
||||
public setAFKChannel(afkChannel: VoiceChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||
@@ -3450,6 +3452,7 @@ export class Widget extends Base {
|
||||
private constructor(client: Client<true>, data: RawWidgetData);
|
||||
private _patch(data: RawWidgetData): void;
|
||||
public fetch(): Promise<Widget>;
|
||||
public imageURL(style?: GuildWidgetStyle): string;
|
||||
public id: Snowflake;
|
||||
public name: string;
|
||||
public instantInvite?: string;
|
||||
@@ -3969,6 +3972,7 @@ export class GuildManager extends CachedManager<Snowflake, Guild, GuildResolvabl
|
||||
public create(options: GuildCreateOptions): Promise<Guild>;
|
||||
public fetch(options: Snowflake | FetchGuildOptions): Promise<Guild>;
|
||||
public fetch(options?: FetchGuildsOptions): Promise<Collection<Snowflake, OAuth2Guild>>;
|
||||
public widgetImageURL(guild: GuildResolvable, style?: GuildWidgetStyle): string;
|
||||
}
|
||||
|
||||
export interface AddOrRemoveGuildMemberRoleOptions {
|
||||
|
||||
Reference in New Issue
Block a user