Repository: discordjs/discord.js
File: packages/discord.js/src/util/Util.js (JavaScript)

Code before:

/**
 * 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.
 * @param {Emoji|EmojiIdentifierResolvable} emoji Emoji identifier to resolve
 * @returns {?(PartialEmoji|PartialEmojiOnlyId)} Supplying a snowflake yields `PartialEmojiOnlyId`.
 * @private
 */
function resolvePartialEmoji(emoji) {
  if (!emoji) return null;
  if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : parseEmoji(emoji);
  const { id, name, animated } = emoji;
  if (!id && !name) return null;
  return { id, name, animated: Boolean(animated) };
}

/**
 * Resolve an emoji object from a Guild
 * @param {Client} client The Client
 * @param {string} emojiId The id of the emoji
 * @returns {GuildEmoji | undefined}
 * @private
 */
export function resolveGuildEmoji(client, emojiId) {
  for (const guild of client.guilds.cache.values()) {
      if (!guild.available) {
          continue;
      }

      const emoji = guild.emojis.cache.get(emojiId);

      if (emoji) {
          return emoji;
      }
  }

  return null;
}

/**
 * Options used to make an error object.
 * @typedef {Object} MakeErrorOptions
 * @property {string} name Error type
 * @property {string} message Message for the error
 * @property {string} stack Stack for the error
 * @private

Review comment (suggestion):
```suggestion
 * Resolves a {@link GuildEmoji} from an emoji id.
 * @param {Client} client The client to use to resolve the emoji
 * @param {Snowflake} emojiId The emoji id to resolve
 * @returns {?GuildEmoji}
```

Code after:

/**
 * 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.
 * @param {Emoji|EmojiIdentifierResolvable} emoji Emoji identifier to resolve
 * @returns {?(PartialEmoji|PartialEmojiOnlyId)} Supplying a snowflake yields `PartialEmojiOnlyId`.
 * @private
 */
function resolvePartialEmoji(emoji) {
  if (!emoji) return null;
  if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : parseEmoji(emoji);
  const { id, name, animated } = emoji;
  if (!id && !name) return null;
  return { id, name, animated: Boolean(animated) };
}

/**
 * Resolves a {@link GuildEmoji} from an emoji id.
 * @param {Client} client The client to use to resolve the emoji
 * @param {Snowflake} emojiId The emoji id to resolve
 * @returns {?GuildEmoji}
 * @private
 */
function resolveGuildEmoji(client, emojiId) {
  for (const guild of client.guilds.cache.values()) {
    if (!guild.available) {
      continue;
    }

    const emoji = guild.emojis.cache.get(emojiId);

    if (emoji) {
      return emoji;
    }
  }

  return null;
}

/**
 * Options used to make an error object.
 * @typedef {Object} MakeErrorOptions
 * @property {string} name Error type
 * @property {string} message Message for the error
 * @property {string} stack Stack for the error
 * @private