mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
refactor: Stickers are free (no more "premium" packs) (#9791)
refactor: stickers are free Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import type { RequestData, REST } from '@discordjs/rest';
|
|||||||
import {
|
import {
|
||||||
Routes,
|
Routes,
|
||||||
type RESTGetAPIStickerResult,
|
type RESTGetAPIStickerResult,
|
||||||
type RESTGetNitroStickerPacksResult,
|
type RESTGetStickerPacksResult,
|
||||||
type Snowflake,
|
type Snowflake,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
|
|
||||||
@@ -12,13 +12,24 @@ export class StickersAPI {
|
|||||||
public constructor(private readonly rest: REST) {}
|
public constructor(private readonly rest: REST) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches all of the nitro sticker packs
|
* Fetches all of the sticker packs
|
||||||
*
|
*
|
||||||
* @see {@link https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs}
|
* @see {@link https://discord.com/developers/docs/resources/sticker#list-sticker-packs}
|
||||||
* @param options - The options for fetching the sticker packs
|
* @param options - The options for fetching the sticker packs
|
||||||
*/
|
*/
|
||||||
public async getNitroStickers({ signal }: Pick<RequestData, 'signal'> = {}) {
|
public async getStickers({ signal }: Pick<RequestData, 'signal'> = {}) {
|
||||||
return this.rest.get(Routes.nitroStickerPacks(), { signal }) as Promise<RESTGetNitroStickerPacksResult>;
|
return this.rest.get(Routes.stickerPacks(), { signal }) as Promise<RESTGetStickerPacksResult>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches all of the sticker packs
|
||||||
|
*
|
||||||
|
* @see {@link https://discord.com/developers/docs/resources/sticker#list-sticker-packs}
|
||||||
|
* @param options - The options for fetching the sticker packs
|
||||||
|
* @deprecated Use {@link getStickers} instead.
|
||||||
|
*/
|
||||||
|
public async getNitroStickers(options: Pick<RequestData, 'signal'> = {}) {
|
||||||
|
return this.getStickers(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ const PermissionsBitField = require('../util/PermissionsBitField');
|
|||||||
const Status = require('../util/Status');
|
const Status = require('../util/Status');
|
||||||
const Sweepers = require('../util/Sweepers');
|
const Sweepers = require('../util/Sweepers');
|
||||||
|
|
||||||
|
let deprecationEmittedForPremiumStickerPacks = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
||||||
* @extends {BaseClient}
|
* @extends {BaseClient}
|
||||||
@@ -358,18 +360,36 @@ class Client extends BaseClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the list of sticker packs available to Nitro subscribers from Discord.
|
* Obtains the list of available sticker packs.
|
||||||
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
||||||
* @example
|
* @example
|
||||||
* client.fetchPremiumStickerPacks()
|
* client.fetchStickerPacks()
|
||||||
* .then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
|
* .then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
async fetchPremiumStickerPacks() {
|
async fetchStickerPacks() {
|
||||||
const data = await this.rest.get(Routes.nitroStickerPacks());
|
const data = await this.rest.get(Routes.stickerPacks());
|
||||||
return new Collection(data.sticker_packs.map(p => [p.id, new StickerPack(this, p)]));
|
return new Collection(data.sticker_packs.map(p => [p.id, new StickerPack(this, p)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the list of available sticker packs.
|
||||||
|
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
||||||
|
* @deprecated Use {@link Client#fetchStickerPacks} instead.
|
||||||
|
*/
|
||||||
|
fetchPremiumStickerPacks() {
|
||||||
|
if (!deprecationEmittedForPremiumStickerPacks) {
|
||||||
|
process.emitWarning(
|
||||||
|
'The Client#fetchPremiumStickerPacks() method is deprecated. Use Client#fetchStickerPacks() instead.',
|
||||||
|
'DeprecationWarning',
|
||||||
|
);
|
||||||
|
|
||||||
|
deprecationEmittedForPremiumStickerPacks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.fetchStickerPacks();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
||||||
* @param {GuildResolvable} guild The guild to fetch the preview for
|
* @param {GuildResolvable} guild The guild to fetch the preview for
|
||||||
|
|||||||
@@ -179,11 +179,11 @@ class Sticker extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the pack this sticker is part of from Discord, if this is a Nitro sticker.
|
* Fetches the pack that contains this sticker.
|
||||||
* @returns {Promise<?StickerPack>}
|
* @returns {Promise<?StickerPack>} The sticker pack or `null` if this sticker does not belong to one.
|
||||||
*/
|
*/
|
||||||
async fetchPack() {
|
async fetchPack() {
|
||||||
return (this.packId && (await this.client.fetchPremiumStickerPacks()).get(this.packId)) ?? null;
|
return (this.packId && (await this.client.fetchStickerPacks()).get(this.packId)) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
4
packages/discord.js/typings/index.d.ts
vendored
4
packages/discord.js/typings/index.d.ts
vendored
@@ -979,7 +979,9 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
||||||
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
||||||
public fetchSticker(id: Snowflake): Promise<Sticker>;
|
public fetchSticker(id: Snowflake): Promise<Sticker>;
|
||||||
public fetchPremiumStickerPacks(): Promise<Collection<Snowflake, StickerPack>>;
|
public fetchStickerPacks(): Promise<Collection<Snowflake, StickerPack>>;
|
||||||
|
/** @deprecated Use {@link fetchStickerPacks} instead. */
|
||||||
|
public fetchPremiumStickerPacks(): ReturnType<Client['fetchStickerPacks']>;
|
||||||
public fetchWebhook(id: Snowflake, token?: string): Promise<Webhook>;
|
public fetchWebhook(id: Snowflake, token?: string): Promise<Webhook>;
|
||||||
public fetchGuildWidget(guild: GuildResolvable): Promise<Widget>;
|
public fetchGuildWidget(guild: GuildResolvable): Promise<Widget>;
|
||||||
public generateInvite(options?: InviteGenerationOptions): string;
|
public generateInvite(options?: InviteGenerationOptions): string;
|
||||||
|
|||||||
Reference in New Issue
Block a user