从 FiveM 获取信息的命令

时间:2021-02-01 18:27:07

标签: javascript node.js discord discord.js fivem

我想用 Visual Studio Code 在 Node.js 中构建一个命令,它将从 FiveM 获取数据,并在消息中显示有多少玩家在线以及是否有队列!

我会发布一张图片,并说明我的意思:enter image description here

我正在使用登录控制台的代码,代码是:

const Gamedig = require('gamedig');
Gamedig.query({
    type: 'fivem',
    host: 'fivem.example.com'
}).then((state) => {
    console.log(state);
}).catch((error) => {
    console.log("Server is offline");
});

请问有没有办法设置为命令并显示“图像”视图!

2 个答案:

答案 0 :(得分:2)

根据 gamedig documentation,回调函数中的 state 参数没有那么多预定义的属性。您可以通过 players.length 属性直接检索在线玩家的数量,通过 state.players.length 方法中的回调函数内的 then() 访问它。但是还有一个 raw 属性似乎返回服务器给您的所有信息,因此您可以尝试解析它并检索任何其他相关信息。

答案 1 :(得分:1)

使用 FiveM 包获取服务器信息。

你可以这样得到球员:

    const FiveM = require("fivem") // Import the npm package.
    const srv = new FiveM.Server('IP:PORT') // Set the IP with port.
    srv.getPlayers().then(data => console.log(data)) // Get & log the data!

或整个服务器对象:

    srv.getServer().then(data => console.log(data)) // Get & log the data!

享受。

相关问题