在Bot命令中使用Web API

时间:2018-07-31 20:19:13

标签: javascript discord discord.js

我有一个运行在侦听http://localhost:8089/ModAPI/?q=online&a=somerandomstring的API服务器,其中q=是命令,而a=是API密钥。我可以从外面打开它。

我希望由不和谐的bot使用!online之类的命令来调用此信息;我怎样才能做到这一点?我真的没头绪。
它应该以文本形式打印。
有人告诉我您必须执行GET请求。那就是我被困住的地方。我找不到适合的代码。要么与JSON解析不起作用。否则我什至无法启动我的机器人。谁知道正确的代码?我希望能够使用!online来调用它,然后它应该从我的链接中发布文本。

API response

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
console.log('Ready!');
});
var request = require('request');

request('http://IP:PORT/ModAPI/?q=online&a=KEY', function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body);// Print the HTML for the Google homepage.
});
client.login('TOKEM');

如果但它会响应控制台:(如果我尝试添加一个命令来调用它,我什至无法启动它。我不知道如何完成它

1 个答案:

答案 0 :(得分:-4)

我建议您检出request Node 软件包并尝试将其与服务器一起使用。对于 GET 请求,这是一个非常好的软件包。

相关问题