Skip to content

Instantly share code, notes, and snippets.

@apos37
Created August 12, 2022 21:33
Show Gist options
  • Save apos37/a83def4535cf22142e6b009f69237e69 to your computer and use it in GitHub Desktop.
Save apos37/a83def4535cf22142e6b009f69237e69 to your computer and use it in GitHub Desktop.
Pylon Bot CSS Reference Command
import { commands } from './command_group';
/**
* Fetch with a command
*/
commands.on(
{
name: 'css',
description: 'Fetch a CSS code reference',
},
(args) => ({
keyword: args.string(),
}),
async (message, { keyword }) => {
// Make lowercase
keyword = keyword.toLowerCase();
// The URL
const url =
'https://raw.githubusercontent.com/mdn/data/main/css/properties.json';
console.log(url);
// Fetch the page
await fetch(url)
.then(function (response) {
// The API call was successful!
return response.json();
})
.then(function (data) {
// console.log(data);
// Make sure it exists
if (data[keyword]) {
const ref = data[keyword];
// console.log(ref);
// Values
const syntax = ref.syntax;
const mdn_url = ref.mdn_url;
// If so, get it and do your magic
message.reply(
new discord.Embed({
title: `${keyword}`,
url: mdn_url,
description: `${syntax}\n\n`,
thumbnail: {
url: 'https://i.imgur.com/uAhTIwr.png',
},
footer: {
text: `CSS Code Reference\n${mdn_url}`,
},
})
);
} else {
message.reply('Sorry, that CSS reference does not exist.');
}
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment