From 7dea73695795a15aad07edb12ed690f98fa17d2e Mon Sep 17 00:00:00 2001 From: Monbrey Date: Wed, 9 Jun 2021 21:22:15 +1000 Subject: [PATCH] fix: suggestions from space's review --- src/structures/APIMessage.js | 5 ++++- src/util/Util.js | 8 +++----- typings/index.d.ts | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/structures/APIMessage.js b/src/structures/APIMessage.js index e46f198f1a32..44cdfaf07614 100644 --- a/src/structures/APIMessage.js +++ b/src/structures/APIMessage.js @@ -4,6 +4,7 @@ const BaseMessageComponent = require('./BaseMessageComponent'); const MessageAttachment = require('./MessageAttachment'); const MessageEmbed = require('./MessageEmbed'); const { RangeError } = require('../errors'); +const { MessageComponentTypes } = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); const MessageFlags = require('../util/MessageFlags'); const Util = require('../util/Util'); @@ -154,7 +155,9 @@ class APIMessage { const embeds = embedLikes.map(e => new MessageEmbed(e).toJSON()); const components = this.options.components?.map(c => - BaseMessageComponent.create(Array.isArray(c) ? { type: 1, components: c } : c).toJSON(), + BaseMessageComponent.create( + Array.isArray(c) ? { type: MessageComponentTypes.ACTION_ROW, components: c } : c, + ).toJSON(), ); let username; diff --git a/src/util/Util.js b/src/util/Util.js index d46015018f0a..75cfad3aef75 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -270,14 +270,12 @@ class Util { /** * Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client. * @param {EmojiIdentifierResolvable} emoji Emoji identifier to resolve - * @returns {Object} Object with possible `animated`, `name`, and `id` properties + * @returns {?RawEmoji} * @private */ static resolvePartialEmoji(emoji) { - if (typeof emoji === 'undefined') return null; - if (typeof emoji === 'string') { - return emoji.length ? (/^\d{17,19}$/.test(emoji) ? { id: emoji } : Util.parseEmoji(emoji)) : null; - } + if (!emoji) return null; + if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : Util.parseEmoji(emoji); const { id, name, animated } = emoji; if (!id && !name) return null; return { id, name, animated }; diff --git a/typings/index.d.ts b/typings/index.d.ts index 5b964b82b5ae..bd256a075b96 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1963,7 +1963,7 @@ declare module 'discord.js' { public static moveElementInArray(array: any[], element: any, newIndex: number, offset?: boolean): number; public static parseEmoji(text: string): { animated: boolean; name: string; id: Snowflake | null } | null; public static resolveColor(color: ColorResolvable): number; - public static resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial; + public static resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial | null; public static verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string; public static setPosition( item: T,