So, I was trying to make a code that makes the bot sending GIFs, but I totally had no idea that what is the actual solution for the bot to not make errors.
Currently hosting my bot on Glitch using hello-express, and using Discord.js to code the thing.
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]
})
});
}
}
And then there you go console log tells me something interesting:
TypeError: GphApiClient is not a function
Change var giphy = GphApiClient(process.env.GIPHYTOKEN);
to var giphy = GphApiClient + giphyToken;
, and make sure giphyToken
is set to your Giphy Token.