[英]I'm having issues using APIs in discord.js
So i'm having an issue defining the price using the coinbase API for node.js, I'm able to send the embed alright, but I'm a bit used what I'm missing in order to display the price.因此,我在使用 node.js 的 coinbase API 定义价格时遇到了问题,我可以发送嵌入,但我有点使用了我所缺少的东西来显示价格。 Thanks in advance!提前致谢!
exports.run = async (client, msg, args) => {
const Discord = require('discord.js');
var Client = require('coinbase').Client;
var client = new Client({'apiKey': 'API KEY',
'apiSecret': 'API SECRET'});
client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, price) {
const av = new Discord.RichEmbed()
let embed = new Discord.RichEmbed()
.setTitle("BTC Price Checker")
.setDescription(price)
.setFooter("Created with ❤️ by anonymous");
msg.channel.send(embed)
msg.delete();
});
}
I dont think this is a discord.js problem might have more luck going to the coinbase-api section of stackoverflow ( https://stackoverflow.com/questions/tagged/coinbase-api?tab=Newest )我不认为这是一个 discord.js 问题可能有更多的运气去 stackoverflow 的 coinbase-api 部分( https://stackoverflow.com/questions/tagged/coinbase-api?tab=Newest )
However a couple things you can try to get your problem,但是,您可以尝试做一些事情来解决您的问题,
1: checking that you have api_key and api_secret set to your key & secret 1:检查您是否已将 api_key 和 api_secret 设置为您的密钥和秘密
var Client = require('coinbase').Client;
var client = new Client({'apiKey': 'API KEY', // here
'apiSecret': 'API SECRET'}); // and here
2: checking for errors 2:检查错误
client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, price) {
if (err) console.log(err)
});
3: checking what the variable "price" is before sending it (console.log) 3:在发送之前检查变量“price”是什么(console.log)
client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, price) {
console.log(price)
});
On a side note some other things i've noticed.在旁注中,我注意到了其他一些事情。
1: you have client set in the parameters of exports.run, you also define it later on. 1:您在exports.run的参数中设置了客户端,您稍后也定义它。 This is bad practice and can lead to some errors later on.这是不好的做法,以后可能会导致一些错误。
var Client = require("coinbase").Client;
exports.run = async (bot) => {
var client = new Client({'apiKey': 'API KEY','apiSecret': 'API SECRET'});
}
2: you define av but you never use it anywhere? 2:您定义了 av 但您从未在任何地方使用它? (line 9) (第 9 行)
3: you delete the message directly after sending it, might be your problem? 3:你发送后直接删除消息,可能是你的问题? (line 15) (第 15 行)
Overall your problems are not with discord.js but rather lie within the request to coingbase / the way you've coded it, try having a look at the documentation for coinbase-api here总的来说,您的问题与 discord.js 无关,而在于对 coingbase 的请求/您的编码方式,请尝试查看 coinbase-api 的文档here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.