When you type hex- <colorName> your bot will return the hex code of any color and a corresponding image.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const fetch = require('node-fetch');
if (context.params.event.content.startsWith('hex-')) {
const args = context.params.event.content.split(' ').slice(1).join(' ');
let url = `https://api.sampleapis.com/css-color-names/colors?name=${args}`
let respond = await fetch(url);
let json = await respond.json();
if(json[0])
{
let hex_ = json[0].hex.replace("#","")
console.log(hex_);
console.log(`0x${hex_}`);
let color = `0x${hex_}`
let image_url = `https://api.alexflipnote.dev/color/image/${hex_}`
await lib.discord.channels['@0.0.3'].messages.create({
channel_id: context.params.event.channel_id,
content: '',
embed: {
title: `${args} | #${hex_}`,
color: parseInt(hex_, 16),
thumbnail: {
url: `${image_url}`,
height: 0,
width: 0,
},
},
});
}
else
{
await lib.discord.channels['@0.0.3'].messages.create({
channel_id: context.params.event.channel_id,
content: `Colour not Identified!`
});
}
}