Discord JS-五名玩家计数
我想创建一个机器人,显示状态为fivem的玩家数量,我如何能以最简单的方式从服务器导入玩家数量?我的服务器在VPS上,机器人将在另一台机器上,因此我无法通过程序进行引用。祝您愉快。您可以使用它,它可以查询不同类型的游戏服务器,FiveM就是其中之一 您可以使用Discord JS-五名玩家计数,discord,discord.js,Discord,Discord.js,我想创建一个机器人,显示状态为fivem的玩家数量,我如何能以最简单的方式从服务器导入玩家数量?我的服务器在VPS上,机器人将在另一台机器上,因此我无法通过程序进行引用。祝您愉快。您可以使用它,它可以查询不同类型的游戏服务器,FiveM就是其中之一 您可以使用npm i gamedig 然后可以修改并使用此示例: const Gamedig=require('Gamedig'); Gamedig.query({ 键入:“fivem”, 主机:“IP”//这需要是一个字符串 端口:端口//这需要是
npm i gamedig
然后可以修改并使用此示例:
const Gamedig=require('Gamedig');
Gamedig.query({
键入:“fivem”,
主机:“IP”//这需要是一个字符串
端口:端口//这需要是一个数字&是可选的,除非您没有使用该游戏服务器类型的默认端口
})。然后((状态)=>{
console.log(state);//您可以使用此输出获取玩家计数。
}).catch((错误)=>{
log(“服务器处于脱机状态”);
});
返回:
(node:15924) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (D:\discordBot5\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:15924) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:15924) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我让它与命令m一起工作!gracze(im-polish)并返回此错误,而不是服务器处于脱机状态或其他任何情况,只有此错误
我的代码:
const { token } = require('./config.json');
const ms = require('ms');
const fs = require('fs');
const { Client } = require('discord.js');
const bot = new Client;
const client = new Client;
const Gamedig = require('gamedig');
bot.on("ready", () => {
console.log(`Zalogowano do bota: ${bot.user.tag}`)
bot.user.setActivity("| ✅ | Ładowanie...", {type: "PLAYING"});
let activeNum = 0;
setInterval(function() {
var scount2 = bot.guilds.size
var ucount = bot.users.size
var currentdate = new Date();
var dateTime = currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " | "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds() + " !";
if (activeNum === 0) {
bot.user.setActivity(`| ✅ | Servery: ${scount2}! `);
activeNum = 1;
}else if (activeNum === 1) {
bot.user.setActivity(`| ✅ | Użytkownicy: ${ucount}! `)
activeNum = 2;
}else if (activeNum === 2) {
bot.user.setActivity(`| ✅ | Pomoc: m!pomoc`)
activeNum = 3;
}else if (activeNum === 3) {
bot.user.setActivity(`| ✅ | Data: ${dateTime}`)
activeNum = 4;
}else if (activeNum === 4) {
bot.user.setActivity(`| ✅ | Status: ✅!`)
activeNum = 0;
}
}, 15 * 1000);
});
bot.on("message", async msg => {
if (msg.author.bot) return;
let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));
if(!prefixes[msg.guild.id]) {
prefixes[msg.guild.id] = {
prefixes: "m!"
};
}
let prefix = prefixes[msg.guild.id].prefixes;
const args = msg.content.split(" ");
let command = msg.content.toLowerCase().split(" ")[0];
command = command.slice(prefix.length)
if (command === "gracze") {
Gamedig.query({
type: 'fivem',
host: '178.33.45.164'
}).then((gracze) => {
msg.channel.send(gracze);
}).catch((error) => {
console.log("server is offline");
msg.channel.send("Server jest offline")
})
}
})
我有两个答案给你
- 固定链接。文件现在也在那里:D