【发布时间】:2021-04-13 18:57:24
【问题描述】:
这可能是不恰当的,但我正在制作一个不和谐的机器人,并且在此过程中我想制作一个“gif”命令。我选择了 Giphy api,因为它似乎是最简单的。但每次我让机器人获取趋势 gif 时,它都会给我相同的 gif。 (附示例) Here you can see he bot sending the same gif 2 times
这是该命令所需的代码:
if (message.content.startsWith(`${prefix}gif`)) {
giphy.trending('gifs', {limit:100})
.then((response) => {
var totalResponses = response.data.length;
var responseIndex = Math.floor((Math.random() * 10) + 1) % totalResponses;
var responseFinal = response.data[responseIndex];
message.channel.send("Here is a gif for you!\n", {
files: [responseFinal.images.fixed_height.url]
}).catch(() => {
message.channel.send('There was an API error, please try later.')
})
})
}
感谢任何答案。
【问题讨论】:
标签: node.js discord discord.js giphy giphy-api