diff --git a/packages/discord.js/src/util/Util.js b/packages/discord.js/src/util/Util.js index 44c0e1e6a4b6..d1be2882e5ad 100644 --- a/packages/discord.js/src/util/Util.js +++ b/packages/discord.js/src/util/Util.js @@ -477,13 +477,14 @@ function resolveColor(color) { if (typeof color === 'string') { if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1)); if (color === 'Default') return 0; - color = Colors[color] ?? parseInt(color.replace('#', ''), 16); + if (/^#?[\da-f]{6}$/i.test(color)) return parseInt(color.replace('#', ''), 16); + color = Colors[color]; } else if (Array.isArray(color)) { color = (color[0] << 16) + (color[1] << 8) + color[2]; } if (color < 0 || color > 0xffffff) throw new DiscordjsRangeError(ErrorCodes.ColorRange); - else if (Number.isNaN(color)) throw new DiscordjsTypeError(ErrorCodes.ColorConvert); + if (typeof color !== 'number' || Number.isNaN(color)) throw new DiscordjsTypeError(ErrorCodes.ColorConvert); return color; }