'Tenor API search varied results
I'm making a Discord bot. Currently where if you type -gif **arguments**
it uses the Tenor API and posts the result of the gif within a message which does work currently fine, but it always gives me the same result with the same search query. My code is below, so how would I make it to where I could vary the search results of a search with the same query?
const Tenor = require("tenorjs").client({
"Key": "Ihaveakeyjustnotshowingit", // https://tenor.com/developer/keyregistration
"Filter": "off", // "off", "low", "medium", "high", not case sensitive
"Locale": "en_US", // Your locale here, case-sensitivity depends on input
"MediaFilter": "minimal", // either minimal or basic, not case sensitive
"DateFormat": "MM/D/YYYY - H:mm:ss A" // Change this accordingly
});
const fs = require('fs');
const discord = require('discord.js');
module.exports = {
name: 'gif',
aliases: ['tenor', 'gifsearch', 'gf'],
category: 'Funny',
utilisation: '{prefix}gif',
execute(client, message, args) {
const msgArgs = message.content.slice(this.name.length + 1)
Tenor.Search.Query(msgArgs, "1").then(Results => {
Results.forEach(Post => {
message.channel.send(Post.itemurl)
});
}).catch(console.error);
},
};
Solution 1:[1]
Tenor.Search.Query(msgArgs, '10').then(Results => {
var totalResponses = Results.length;
var responseIndex = Math.floor(Math.random() * 10 + 1) % totalResponses;
var responseFinal = Results[responseIndex];
message.channel.send(responseFinal.itemurl)
}).catch(console.error);
}
Request 10 responses, choose one random from the incoming responses and use it in the message.channel.send section! Note: Tried, works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | thumbsup |