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

cannot convert color to a number #10107

Closed
DarkPheonix2122 opened this issue Jan 29, 2024 · 9 comments
Closed

cannot convert color to a number #10107

DarkPheonix2122 opened this issue Jan 29, 2024 · 9 comments
Labels

Comments

@DarkPheonix2122
Copy link

DarkPheonix2122 commented Jan 29, 2024

Which package is this bug report for?

discord.js

Issue description

TypeError [ColorConvert]: Unable to convert color to a number.
    at resolveColor (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\discord.js\src\util\Util.js:290:63)
    at EmbedBuilder.setColor (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\discord.js\src\structures\EmbedBuilder.js:23:36)  
    at Object.run (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\commands\prefix\music\volume.js:26:14)
    at run (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\events\client\messageCreate.js:77:13)
    at Client.emit (node:events:513:28)
    at MessageCreateAction.handle (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\discord.js\src\client\actions\MessageCreate.js:28:14)
    at module.exports [as MESSAGE_CREATE] (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
    at WebSocketManager.<anonymous> (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
    at WebSocketManager.emit (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    at WebSocketShard.<anonymous> (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\@discordjs\ws\dist\index.js:1173:51)
    at WebSocketShard.emit (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    at WebSocketShard.onMessage (C:\Users\jcaum\Documents\vscode projects\HiiGher BOT\node_modules\@discordjs\ws\dist\index.js:988:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ColorConvert'
}

Code sample

/* eslint-disable no-unused-vars */
const { EmbedBuilder } = require("discord.js");

module.exports = {
    name: "volume",
    category: "Music",
    aliases: [ "v" ],
    description: "Set Volume",
    usage: [],
    dirname: __dirname,
    usage: [ "<Number of volume between 0 - 100>" ],
    owner: false,
    run: async(client, message, args) => {
        const memberVC = message.member.voice.channel;
        if (!memberVC) return message.reply(`${message.error} | You must be in a voice channel!`);

        const clientVC = message.guild.members.me.voice.channel;
        if (!clientVC) return message.reply(`${message.error} | I'm not on any voice channel!`);

        if (memberVC !== clientVC) return message.reply(`${message.error} | You must be in the same channel as ${message.client.user}!`);

        const queue = client.distube.getQueue(message);
        if (!queue) return message.reply(`${message.error} | There is no music playing!`);

        const embed = new EmbedBuilder()
            .setColor("Blurple")
            .setFooter({ text: `Request by ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });

        let volume = parseInt(args[0]);
        if (!volume) {
            embed.setDescription(`Current **Volume** : \`${queue.volume}\`%`);
            return message.channel.send({ embeds: [embed] });
        }

        if (isNaN(volume)) return message.reply(`${message.error} | Please enter a valid number!`)

        if (volume < 0)  volume = 0;
        if (volume > 100) volume = 100;

        client.distube.setVolume(message, volume);

        embed.setDescription(`${client.emoji.volume} | Successfully changed the **Volume** to \`${volume}\`%`);
        message.channel.send({ embeds: [embed] });

    }
}

Versions

discord.js@latest
node@18.15.0
npm@9.5.0

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GuildMessages

I have tested this issue on a development release

No response

@sdanialraza
Copy link
Contributor

I can't seem to reproduce this issue, and it also looks like you're violating YouTube TOS and by proxy Discord's TOS so don't think you'd be getting much help because of that.

@almostSouji
Copy link
Member

Please use a minimal reproducible sample you tested outside of the context of your production code (or a reduced version) so we can test and evaluate it in isolation without a major setup. I do currently not see how "Blurple" can throw here, given you are on "latest" v14.14.1

I tested the following code

const { EmbedBuilder } = require("discord.js");
console.log(new EmbedBuilder().setColor("Blurple"));

which prints

EmbedBuilder { data: { color: 5793266 } }

without errors, as expected.

@DarkPheonix2122
Copy link
Author

i am aware that i might be violating youtubes tos but im not using a proxy? this bots was just made so i can listen to music without opening youtube, im using my own cookie too and im the only one using it, its not just this code either, its every line of code every time i try to create an embed builder, no matter what file or command it either gived me invalid permissions error or thhis error everytime i try to create an embed, also i will update that line of code to work on a standalone rq

@DarkPheonix2122
Copy link
Author

DarkPheonix2122 commented Jan 30, 2024

const client = new Discord.Client({
  intents: Object.keys(Discord.GatewayIntentBits).map((a)=>{
    return Discord.GatewayIntentBits[a]
  }),
});
client.on(Discord.Events.ClientReady, async client => {
    let guild = client.guilds.cache.get("guildId");
    let channel = guild.channels.cache.get("ChannelId");
    const embed = new Discord.EmbedBuilder()
      .setColor("BLURPLE")
      .setTitle("Ready")
      .setDescription(`Logged in as <@${client.user.id}>!`)
      .addFields(
        { name: `Commands`, value: `Loaded ${client.commands.size} commands!`, inline: true},
        { name: `Guilds`, value: `loaded in ${client.guilds.cache.size} servers!`, inline: true}
        )
      .setTimestamp()
      .setColor("Blurple")
      .setFooter("Hiigher Startup");
      channel.send({embeds : [embed]})
})
client.on(Discord.Events.MessageCreate, async message => {
    if(message.content.includes("hq.embed")){
        const newEmbed = new Discord.EmbedBuilder()
        .setColor('Blurple')
        .setDescription("discription")
        message.channel.send({ embeds: [newEmbed] })
    }
})
client.login(token)```

that is basically my ready file and example command, when starting bot it also shows this error because its suppost to send that startup embed to the specified channel in the group.

@sdanialraza
Copy link
Contributor

You have BLURPLE there, change that to Blurple

@almostSouji
Copy link
Member

Usage error, not a bug in the library

@almostSouji almostSouji closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
@DarkPheonix2122
Copy link
Author

DarkPheonix2122 commented Jan 30, 2024

You have BLURPLE there, change that to Blurple

it is Blurple i just pasted from my test file lmao doesnt matter what it is, i can do hex codes and it will give same error

@DarkPheonix2122
Copy link
Author

doesnt matter what i do, ive tried color codes, hex colors and just simple text and it just gives the error everytime, i did the code above and console logged it and it outputted with no errors but as soon as i add channel.send to anything it gives that error

@sdanialraza
Copy link
Contributor

As Souji said, it's an usage error, not a bug in the library, please ask in the Discord server if you need help using discord.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants