Showing
1 changed file
with
35 additions
and
0 deletions
commands/lospi.js
0 → 100644
| 1 | +const { SlashCommandBuilder } = require('@discordjs/builders'); | ||
| 2 | +const { MessageEmbed } = require('discord.js'); | ||
| 3 | +const axios = require("axios"); | ||
| 4 | +const cheerio = require("cheerio"); | ||
| 5 | + | ||
| 6 | +module.exports = { | ||
| 7 | + data: new SlashCommandBuilder() | ||
| 8 | + .setName('시세') | ||
| 9 | + .setDescription('현재 100크리스탈 당 골드 시세를 조회합니다.'), | ||
| 10 | + async execute(interaction) { | ||
| 11 | + async function getHTML() { | ||
| 12 | + try { | ||
| 13 | + return await axios.get("https://www.mgx.kr/lostark/goldexchange/"); | ||
| 14 | + } catch (error) { | ||
| 15 | + console.error(error); | ||
| 16 | + } | ||
| 17 | + }; | ||
| 18 | + await getHTML().then(html=>{ | ||
| 19 | + const $ = cheerio.load(html.data); | ||
| 20 | + const buyValue = $("div.price.buy span").text(); | ||
| 21 | + const sellValue = $("div.price.sell span").text(); | ||
| 22 | + const embed = new MessageEmbed() | ||
| 23 | + .setTitle("크리스탈 시세") | ||
| 24 | + .setDescription("100<:bluecrystal:952747773097295932>당 "+$("div.searched_time").text()) | ||
| 25 | + .setColor("#CECEF6") | ||
| 26 | + .addFields( | ||
| 27 | + {name: "크리스탈 구매가", value: `${buyValue}<:gold:952804483237289994>`, inline: true}, | ||
| 28 | + {name: "\u200b", value: "\u200b", inline: true}, | ||
| 29 | + {name: "크리스탈 판매가", value: `${sellValue}<:gold:952804483237289994>`, inline: true} | ||
| 30 | + ); | ||
| 31 | + interaction.reply({embeds: [embed], allowedMentions: {repliedUser: false}}); | ||
| 32 | + }); | ||
| 33 | + | ||
| 34 | + }, | ||
| 35 | +}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment