Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color from string not applying due to case sensitivity, yet no error #8932

Closed
Ethorbit opened this issue Dec 16, 2022 · 1 comment · Fixed by #8933
Closed

Color from string not applying due to case sensitivity, yet no error #8932

Ethorbit opened this issue Dec 16, 2022 · 1 comment · Fixed by #8933

Comments

@Ethorbit
Copy link

Which package is this bug report for?

discord.js

Issue description

  1. Make bot post embed message, but set the embed color to one of these strings in all lowercase
  2. In the Discord client, the embed will appear black, instead of the color it is supposed to be.

Usually when you pass a color that's not valid, it generates an error, but for some reason the case insensitive colors pass without error and then don't apply.

Example

Code sample

client.on("messageCreate", msg => {
    if (msg.author.bot)
        return;

    try
    {
        const embed = new EmbedBuilder();
        embed.setColor(msg.content); 
        embed.setTitle("Selected color");
        embed.setDescription(msg.content);
        msg.channel.send({embeds: [embed]});
    }  
    catch 
    {
        const embed = new EmbedBuilder();
        embed.setTitle("Incorrect color");
        embed.setDescription(`${msg.content} is not a valid color.`);
        msg.channel.send({embeds: [embed]});
    }
});

Package version

14.7.1

Node.js version

19.2.0

Operating system

Arch Linux 5.15.83-1-lts

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMessages, MessageContent

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

The issue lies on this line:

color = Colors[color] ?? parseInt(color.replace('#', ''), 16);

As we already know, a lower case variant of any colour is not valid. Thus, parseInt(color.replace('#', ''), 16) is used for color instead. This is doing parseInt('b', 16) (in this case) and returns 11 - the first & only match.

I am not sure if fixing this would be major, however.

iCrawl pushed a commit that referenced this issue Dec 16, 2022
letheist pushed a commit to deepcord/discord.js that referenced this issue Oct 13, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants