如何让机器人通过 Giphy API 正确发送 GIF?
How do I let a bot send a GIF via Giphy API correctly?
所以,我试图编写一个代码让机器人发送 GIF,但我完全不知道机器人不出错的实际解决方案是什么。
目前正在使用 hello-express 在 Glitch 上托管我的机器人,并使用 Discord.js 对其进行编码。
const GphApiClient = require("giphy-js-sdk-core");
var giphy = GphApiClient(process.env.GIPHYTOKEN);
client.on("message", async message => {
if (message.content.startsWith(`${prefix}gif`)) {
giphy.search("gifs", { q: "fail" })
.then(response => {
var totalResponses = response.data.length;
var responseIndex = Math.floor((Math.random() * 10) + 1) % totalResponses;
var responseFinal = response.data[responseIndex]
message.channel.send({
files: [responseFinal.images.fixed_height.url]
})
});
}
}
然后控制台日志告诉我一些有趣的事情:
TypeError: GphApiClient is not a function
将 var giphy = GphApiClient(process.env.GIPHYTOKEN);
更改为 var giphy = GphApiClient + giphyToken;
,并确保 giphyToken
设置为您的 Giphy 令牌。
所以,我试图编写一个代码让机器人发送 GIF,但我完全不知道机器人不出错的实际解决方案是什么。
目前正在使用 hello-express 在 Glitch 上托管我的机器人,并使用 Discord.js 对其进行编码。
const GphApiClient = require("giphy-js-sdk-core");
var giphy = GphApiClient(process.env.GIPHYTOKEN);
client.on("message", async message => {
if (message.content.startsWith(`${prefix}gif`)) {
giphy.search("gifs", { q: "fail" })
.then(response => {
var totalResponses = response.data.length;
var responseIndex = Math.floor((Math.random() * 10) + 1) % totalResponses;
var responseFinal = response.data[responseIndex]
message.channel.send({
files: [responseFinal.images.fixed_height.url]
})
});
}
}
然后控制台日志告诉我一些有趣的事情:
TypeError: GphApiClient is not a function
将 var giphy = GphApiClient(process.env.GIPHYTOKEN);
更改为 var giphy = GphApiClient + giphyToken;
,并确保 giphyToken
设置为您的 Giphy 令牌。