Answer the question
In order to leave comments, you need to log in
How to output server data to discord bot via embed?
I’ll clarify right away in node js and I’m weak in coding
Need help, possibly a financial reward.
In principle, I understand how to build a simple discord bot, but the task is as follows:
there is a library: https://www.npmjs.com/package/gamedig#usage-from-c...
You need to display the
name
map
Players & maxplayers
connect data on the command
How bind them to embed (and how can they be updated?) thanks
const Discord = module.require("discord.js");
const Gamedig = require('gamedig');
const fs = require("fs");
const qs = require("querystring");
module.exports.run = async (bot,message,args) => {
message.delete().catch();
Gamedig.query({
type: 'arkse',
host: '85.190.155.194',
port: '27015'
}).then((state) => {
console.log(state);
}).catch((error) => {
console.log("Server is offline");
});
const embed = new Discord.RichEmbed()
.setTitle(name);
.setColor((online ? 0x37963F : 0x933836))
.addField(Map, true)
.addField(Players/maxplayers, true)
.addField(Connect:, true)
.setTimestamp()
message.channel.send(embed);
};
module.exports.help = {
name: "ark"
};
Answer the question
In order to leave comments, you need to log in
.then(()=>{})
.catch(()=>{})
// Создание запроса к библиотеке
Gamedig.query({
type: 'arkse',
host: '85.190.155.194',
port: '27015'
})
// Код который вызовется при успешном запросе т.е. ответ, данные получены
.then((state) => {
const embed = new Discord.RichEmbed()
.setTitle(state.name)
.addField(state.map, true)
.addField(state.players.length/state.maxplayers, true)
.addField(state.connect:, true)
.setTimestamp();
message.channel.send(embed);
})
// Произошла ошибка
.catch((e)=>{/*ну а тут обработчик ошибки*/})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question