将来自 api 的信息发送到消息中的 discord (discord.js)
sending info from api to discord in a message (discord.js)
嘿,我有一个关于如何将数据发送到 discord.js 中的消息的问题。我现在使用的代码有点工作。它只是给我响应 [Object Object]
client.on("message", msg => {
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random',
headers: {
accept: 'application/json',
'X-RapidAPI-Host': 'matchilling-chuck-norris-jokes-v1.p.rapidapi.com',
'X-RapidAPI-Key': '0f787e5af5msh468814e0b585173p1cacafjsn7d774dfb44ff'
}
}
if(msg.content === "chuck"){
axios.request(options).then(function (response) {
let datachuck = response.data
msg.channel.send(`${datachuck}`)
console.log(response.data)
}).catch(function (error) {
console.error(error);
});
}
})
respone.data 不是对象。这就是为什么我得到 [object, object]
所以解决方案是让datachuck = response.data.value
嘿,我有一个关于如何将数据发送到 discord.js 中的消息的问题。我现在使用的代码有点工作。它只是给我响应 [Object Object]
client.on("message", msg => {
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random',
headers: {
accept: 'application/json',
'X-RapidAPI-Host': 'matchilling-chuck-norris-jokes-v1.p.rapidapi.com',
'X-RapidAPI-Key': '0f787e5af5msh468814e0b585173p1cacafjsn7d774dfb44ff'
}
}
if(msg.content === "chuck"){
axios.request(options).then(function (response) {
let datachuck = response.data
msg.channel.send(`${datachuck}`)
console.log(response.data)
}).catch(function (error) {
console.error(error);
});
}
})
respone.data 不是对象。这就是为什么我得到 [object, object] 所以解决方案是让datachuck = response.data.value