2

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

Raymond
  • 51
  • 1
  • 2
  • 16

1 Answers1

0

Change var giphy = GphApiClient(process.env.GIPHYTOKEN); to var giphy = GphApiClient + giphyToken;, and make sure giphyToken is set to your Giphy Token.

Vendetta
  • 2,078
  • 3
  • 13
  • 31
  • That helped me, but if I perform the GIF command, the thing gives me the error: `TypeError: giphy.search is not a function`, but I'm sure that I have the developer pack installed... – Raymond Oct 19 '19 at 04:41
  • I mean, personally, I have made discord bots simply use the built-in `/giphy ` message command, just a thought. Let me look into the new error. – Vendetta Oct 19 '19 at 16:49
  • 1
    @RaymondHsu I found this on the [GIPHY Developers website](https://developers.giphy.com/docs/resource/#code-examples): `//javascript, jQuery var xhr = $.get("http://api.giphy.com/v1/gifs/search?q=ryan+gosling&api_key=YOUR_API_KEY&limit=5"); xhr.done(function(data) { console.log("success got data", data); });` – Vendetta Oct 19 '19 at 16:52