Get the Genshin Impact basic character details by using this prefix command !gi-character <name> (eg. !gi-character ganyu)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const genshin = require('genshin-api');
const result = await lib.http.request['@1.1.7'].get({
url: `https://api.genshin.dev/characters/`,
});
const CHARACTERS = result.data;
let characterName =
context.params.event.content.split(' ')?.slice(1).join('') || '';
if (characterName && CHARACTERS.includes(characterName.toLowerCase())) {
const data = await genshin.Characters(characterName);
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
message_reference: {
message_id: `${context.params.event.id}`,
},
embeds: [
{
type: 'rich',
title: `${data.name}`,
description: `${data.description}`,
color: 0x00ffff,
fields: [
{
name: `:sparkles: Vision`,
value: `${data.vision}`,
inline: true,
},
{
name: `:crossed_swords: Weapon`,
value: `${data.weapon}`,
inline: true,
},
{
name: `:house: Nation`,
value: `${data.nation}`,
inline: true,
},
{
name: `:gem: Rarity`,
value: `${data.rarity}`,
inline: true,
},
{
name: `:star: Constellation`,
value: `${data.constellation}`,
inline: true,
},
{
name: `:partying_face: Birthday`,
value: `${data.birthday.split('-')[1]}-${
data.birthday.split('-')[2]
}`,
inline: true,
},
],
thumbnail: {
url: `https://cdn.discordapp.com/attachments/990077404661837854/1007950564379873290/de8hzqj-45443592-d7d8-4a12-bed7-663747aa5d0c.png`,
height: 0,
width: 0,
},
image: {
url: `${data.image}`,
height: 0,
width: 0,
},
footer: {
text: `by fidilen#1432`,
icon_url: `https://cdn.discordapp.com/attachments/990077404661837854/1007947114837463160/ganyu.gif`,
},
},
],
});
} else {
let counter = 0;
let formattedChars = CHARACTERS.map((c) => {
++counter;
if (counter % 4 == 0) {
return '\n`' + c + '`';
}
return '`' + c + '`';
});
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `:x: Invalid Character Name`,
description: [
`Please choose a character name from below:`,
formattedChars.join(' | '),
'\n\nUse the prefix on this format:\n`!gi-character ` (eg. !gi-character ganyu).',
].join('\n'),
color: 0xff0000,
thumbnail: {
url: `https://cdn.discordapp.com/attachments/990077404661837854/1007950564379873290/de8hzqj-45443592-d7d8-4a12-bed7-663747aa5d0c.png`,
height: 0,
width: 0,
},
footer: {
text: `by fidilen#1432`,
icon_url: `https://cdn.discordapp.com/attachments/990077404661837854/1007947114837463160/ganyu.gif`,
},
},
],
});
}