Install this command: https://pastebin.com/U2Ywc9cR See a preview of a Color with more Information, like Name, RGB Value and INT Value. Preview: https://media.discordapp.net/attachments/931273194160160829/948874374633623573/unknown.png
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios').default;
const subcommand = context.params.event.data.options[0].name;
function getIntFromHex(colorCode) {
return parseInt(colorCode);
}
if (subcommand === 'show') {
let colorCode = context.params.event.data.options[0].options[0].value;
const startsWithHashtag = colorCode.startsWith('#');
const startsWith0x = colorCode.startsWith('0x');
console.log(`colorCode`, colorCode);
if (startsWithHashtag || startsWith0x) {
const cleanColor = colorCode.replace('0x', '').replace('#', '');
const url = 'https://www.thecolorapi.com/id?&hex=' + cleanColor;
const htmlURL =
'https://www.thecolorapi.com/id?format=html&hex=' + cleanColor;
const data = await axios.get(url);
const json = data.data;
const colorName = json.name.value;
const hexValue = json.hex.clean;
const rgbValue = json.rgb.r + ', ' + json.rgb.g + ', ' + json.rgb.b;
const intValue = getIntFromHex(colorCode.replace('#', '0x'));
const imgURL =
'https://serux.pro/rendercolour?hex=' +
hexValue +
'&height=100&width=225';
await lib.discord.channels['@release'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `Color Information`,
description: `[More Details](${htmlURL})`,
color: `${intValue}`,
fields: [
{
name: `**Name**`,
value: `${colorName}`,
inline: false,
},
{
name: `**HEX**`,
value: `${hexValue}`,
inline: true,
},
{
name: `**RGB**`,
value: `${rgbValue}`,
inline: true,
},
{
name: `**INT**`,
value: `${intValue}`,
inline: true,
},
],
image: {
url: `${imgURL}`,
height: 0,
width: 0,
},
footer: {
text: `Chillihero`, //change this to what ever you want
icon_url: `https://cdn.discordapp.com/avatars/714441418457874452/9643b7f26ccbed96dc7ad12acc733331.png`, //change this too
},
},
],
});
} else {
console.log('Please use a valid Hex Color Code | ', colorCode);
//TODO: Add better error message
}
}