mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
docs: Remove duplicate APIEmoji (#9880)
* types: remove duplicate type definition * chore: add `Emoji` to method * types(resolvePartialEmoji): overload method
This commit is contained in:
@@ -3,14 +3,6 @@
|
|||||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||||
const Base = require('./Base');
|
const Base = require('./Base');
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents raw emoji data from the API
|
|
||||||
* @typedef {APIEmoji} RawEmoji
|
|
||||||
* @property {?Snowflake} id The emoji's id
|
|
||||||
* @property {?string} name The emoji's name
|
|
||||||
* @property {?boolean} animated Whether the emoji is animated
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
|
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
|
||||||
* @extends {Base}
|
* @extends {Base}
|
||||||
@@ -101,8 +93,3 @@ class Emoji extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.Emoji = Emoji;
|
exports.Emoji = Emoji;
|
||||||
|
|
||||||
/**
|
|
||||||
* @external APIEmoji
|
|
||||||
* @see {@link https://discord.com/developers/docs/resources/emoji#emoji-object}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -79,13 +79,21 @@ async function fetchRecommendedShardCount(token, { guildsPerShard = 1_000, multi
|
|||||||
return Math.ceil((shards * (1_000 / guildsPerShard)) / multipleOf) * multipleOf;
|
return Math.ceil((shards * (1_000 / guildsPerShard)) / multipleOf) * multipleOf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A partial emoji object.
|
||||||
|
* @typedef {Object} PartialEmoji
|
||||||
|
* @property {boolean} animated Whether the emoji is animated
|
||||||
|
* @property {Snowflake|undefined} id The id of the emoji
|
||||||
|
* @property {string} name The name of the emoji
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses emoji info out of a string. The string must be one of:
|
* Parses emoji info out of a string. The string must be one of:
|
||||||
* * A UTF-8 emoji (no id)
|
* * A UTF-8 emoji (no id)
|
||||||
* * A URL-encoded UTF-8 emoji (no id)
|
* * A URL-encoded UTF-8 emoji (no id)
|
||||||
* * A Discord custom emoji (`<:name:id>` or `<a:name:id>`)
|
* * A Discord custom emoji (`<:name:id>` or `<a:name:id>`)
|
||||||
* @param {string} text Emoji string to parse
|
* @param {string} text Emoji string to parse
|
||||||
* @returns {APIEmoji} Object with `animated`, `name`, and `id` properties
|
* @returns {?PartialEmoji}
|
||||||
*/
|
*/
|
||||||
function parseEmoji(text) {
|
function parseEmoji(text) {
|
||||||
if (text.includes('%')) text = decodeURIComponent(text);
|
if (text.includes('%')) text = decodeURIComponent(text);
|
||||||
@@ -94,10 +102,16 @@ function parseEmoji(text) {
|
|||||||
return match && { animated: Boolean(match[1]), name: match[2], id: match[3] };
|
return match && { animated: Boolean(match[1]), name: match[2], id: match[3] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A partial emoji object with only an id.
|
||||||
|
* @typedef {Object} PartialEmojiOnlyId
|
||||||
|
* @property {Snowflake} id The id of the emoji
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
|
* Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
|
||||||
* @param {EmojiIdentifierResolvable} emoji Emoji identifier to resolve
|
* @param {Emoji|EmojiIdentifierResolvable} emoji Emoji identifier to resolve
|
||||||
* @returns {?RawEmoji}
|
* @returns {?(PartialEmoji|PartialEmojiOnlyId)} Suppling a snowflake yields `PartialEmojiOnlyId`.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function resolvePartialEmoji(emoji) {
|
function resolvePartialEmoji(emoji) {
|
||||||
|
|||||||
15
packages/discord.js/typings/index.d.ts
vendored
15
packages/discord.js/typings/index.d.ts
vendored
@@ -3202,9 +3202,10 @@ export function makeError(obj: MakeErrorOptions): Error;
|
|||||||
export function makePlainError(err: Error): MakeErrorOptions;
|
export function makePlainError(err: Error): MakeErrorOptions;
|
||||||
export function mergeDefault(def: unknown, given: unknown): unknown;
|
export function mergeDefault(def: unknown, given: unknown): unknown;
|
||||||
export function moveElementInArray(array: unknown[], element: unknown, newIndex: number, offset?: boolean): number;
|
export function moveElementInArray(array: unknown[], element: unknown, newIndex: number, offset?: boolean): number;
|
||||||
export function parseEmoji(text: string): { animated: boolean; name: string; id: Snowflake | null } | null;
|
export function parseEmoji(text: string): PartialEmoji | null;
|
||||||
export function resolveColor(color: ColorResolvable): number;
|
export function resolveColor(color: ColorResolvable): number;
|
||||||
export function resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial<APIPartialEmoji> | null;
|
export function resolvePartialEmoji(emoji: Snowflake): PartialEmojiOnlyId;
|
||||||
|
export function resolvePartialEmoji(emoji: Emoji | EmojiIdentifierResolvable): PartialEmoji | null;
|
||||||
export function verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string;
|
export function verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string;
|
||||||
export function setPosition<T extends Channel | Role>(
|
export function setPosition<T extends Channel | Role>(
|
||||||
item: T,
|
item: T,
|
||||||
@@ -6159,6 +6160,16 @@ export interface PartialChannelData {
|
|||||||
rateLimitPerUser?: number;
|
rateLimitPerUser?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PartialEmoji {
|
||||||
|
animated: boolean;
|
||||||
|
id: Snowflake | undefined;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PartialEmojiOnlyId {
|
||||||
|
id: Snowflake;
|
||||||
|
}
|
||||||
|
|
||||||
export type Partialize<
|
export type Partialize<
|
||||||
T extends AllowedPartial,
|
T extends AllowedPartial,
|
||||||
NulledKeys extends keyof T | null = null,
|
NulledKeys extends keyof T | null = null,
|
||||||
|
|||||||
@@ -181,6 +181,10 @@ import {
|
|||||||
PartialGuildMember,
|
PartialGuildMember,
|
||||||
PartialMessage,
|
PartialMessage,
|
||||||
PartialMessageReaction,
|
PartialMessageReaction,
|
||||||
|
resolvePartialEmoji,
|
||||||
|
PartialEmojiOnlyId,
|
||||||
|
Emoji,
|
||||||
|
PartialEmoji,
|
||||||
} from '.';
|
} from '.';
|
||||||
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||||
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
||||||
@@ -2363,3 +2367,9 @@ expectType<true>(partialUser.partial);
|
|||||||
expectType<null>(partialUser.username);
|
expectType<null>(partialUser.username);
|
||||||
expectType<null>(partialUser.tag);
|
expectType<null>(partialUser.tag);
|
||||||
expectType<null>(partialUser.discriminator);
|
expectType<null>(partialUser.discriminator);
|
||||||
|
|
||||||
|
declare const emoji: Emoji;
|
||||||
|
{
|
||||||
|
expectType<PartialEmojiOnlyId>(resolvePartialEmoji('12345678901234567'));
|
||||||
|
expectType<PartialEmoji | null>(resolvePartialEmoji(emoji));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user