Search after Discord Bots Information via the BotGG Autocode API. Full working snippet to get all Informations and Stats from BotGG. Command Template: https://pastebin.com/kJj3bSeX Command: /search-bot <botname>
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let channelID = context.params.event.channel_id;
let botname = context.params.event.data.options[0].value;
botname = botname.toLowerCase();
try {
let result = await lib.botgg.bots['@0.0.3'].retrieve({
bot_slug: `${botname}`,
});
let {
slug,
short_description,
full_description,
cover_image,
website_url,
twitter_username,
tiktok_username,
patreon_username,
views_count,
upvotes_count,
member_count,
server_count,
custom_invite_link,
author,
tags,
client_id,
} = result;
full_description = full_description.replace(/#/g, '');
full_description = full_description.replace(/\*/g, '');
full_description = full_description.replace(/---/g, '');
let tagString = tags.map((tag) => `\`${tag.label}\``).join(' ');
let embed = {
type: 'rich',
title: `${botname}`,
description: `${short_description}\n**Long Description**
\`\`\`${full_description}\`\`\``,
color: 0x6759ff,
fields: [
{
name: `Stats`,
value: `**ClientID**: \`${client_id}\`\n**Views**: \`${views_count}\`\n**Votes**: \`${upvotes_count}\`\n**Members**: \`${member_count}\`\n**Servers**: \`${server_count}\`\n`,
},
{
name: `Tags`,
value: `${tagString}`,
},
],
footer: {
text: `Bot created by ${author.display_name}`,
icon_url: `${author.full_avatar_url}`,
},
url: `https://bot.gg/bot/${slug}`,
};
// if (thumbnail_url !== undefined) {
// embed.thumbnail = {
// url: `${thumbnail_url}`,
// height: 0,
// width: 0,
// };
// }
if (cover_image !== null) {
embed.image = {
url: `${cover_image}`,
height: 0,
width: 0,
};
}
let components = [];
if (custom_invite_link !== null) {
components.push({
style: 5,
label: `Invite`,
url: `${custom_invite_link}`,
disabled: false,
type: 2,
});
}
if (website_url !== null) {
components.push({
style: 5,
label: `Website`,
url: `https://${website_url}`,
disabled: false,
type: 2,
});
}
if (twitter_username !== null) {
components.push({
style: 5,
label: `Twitter`,
url: `https://twitter.com/${twitter_username}`,
disabled: false,
type: 2,
});
}
if (tiktok_username !== null) {
components.push({
style: 5,
label: `TikTok`,
url: `https://www.tiktok.com/@${tiktok_username}`,
disabled: false,
type: 2,
});
}
if (patreon_username !== null) {
components.push({
style: 5,
label: `Patreon`,
url: `https://www.patreon.com/${patreon_username}`,
disabled: false,
type: 2,
});
}
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: channelID,
content: '',
embeds: [embed],
components: [
{
type: 1,
components: components,
},
],
});
return;
} catch (e) {
console.error(e);
//Bot not found
if (e.message.includes('not found')) {
console.log(`bot not found`);
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: `${channelID}`,
content: `No Bot found with that Name. Please use a specific name!`,
});
return;
} else {
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: `${channelID}`,
content: `Something went wrong :(`,
});
}
}