[英]How to create an embed for statistical information provided by my Discord bot (Covid Statistics)
我創建了一個 Discord 機器人,它將根據命令為我提供任何國家/地區的 Covid 統計數據,但是它僅以原始文本顯示給我,我見過這樣的嵌入圖像:
我有興趣在我的機器人回復中像這樣顯示我的數據,這是我正在使用的代碼:
const axios = require('axios');
const countries = require("./countries.json");
const url = 'https://api.covid19api.com/total/country/';
const WAKE_COMMAND = 'cases';
client.on('message', async (msg) => {
const content = msg.content.split(/[ ,]+/);
if(content[0] === WAKE_COMMAND){
if(content.length > 2){
msg.reply("Too many arguments...")
}
else if(content.length === 1){
msg.reply("Not enough arguments")
}
else if(!countries[content[1]]){
msg.reply("Wrong country format")
}
else{
const slug = content[1]
const payload = await axios.get(`${url}${slug}`)
const covidData = payload.data.pop();
msg.reply(`Confirmed: ${covidData.Confirmed}, Deaths: ${covidData.Deaths}, Recovered: ${covidData.Recovered}, Active: ${covidData.Active} `)
}
}
});
任何關於我應該如何重新排列我的代碼看起來更像上面嵌入的幫助將不勝感激。
謝謝!
您可以使用MessageEmbed class 執行此操作。
這是一個使用它的例子:
const embed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("A title")
.setDescription("A description")
.setTimestamp()
message.channel.send(embed);
// You can also use the code below, in your case
msg.reply(embed);
您可以在此處找到更多示例
如果你想創建像 ProDyno 一樣的東西,你需要在 MessageEmbed class 上使用.addLine
方法,這將允許你將inline
之類的東西切換為true
,這樣你就可以將統計信息放在一起。 例如:
.addFields(
{ name: 'Inline title', value: 'Inline text', inline: true },
{ name: 'Inline title', value: 'Inline text', inline: true },
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.