Skip to content

Commit

Permalink
fix(resolveColor): invalid colors (#8933)
Browse files Browse the repository at this point in the history
Fixes #8932
  • Loading branch information
almeidx committed Dec 16, 2022
1 parent cbafd47 commit c76e170
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/discord.js/src/util/Util.js
Expand Up @@ -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;
}
Expand Down

0 comments on commit c76e170

Please sign in to comment.