【问题标题】:How do I let a bot send a GIF via Giphy API correctly?如何让机器人通过 Giphy API 正确发送 GIF?
【发布时间】:2020-02-15 17:43:46
【问题描述】:

所以,我试图编写一个代码让机器人发送 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

【问题讨论】:

    标签: javascript discord.js giphy-api


    【解决方案1】:

    var giphy = GphApiClient(process.env.GIPHYTOKEN); 更改为var giphy = GphApiClient + giphyToken;,并确保将giphyToken 设置为您的Giphy 令牌。

    【讨论】:

    • 这对我有帮助,但如果我执行 GIF 命令,则会出现错误:TypeError: giphy.search is not a function,但我确定我已经安装了开发人员包...
    • 我的意思是,就我个人而言,我已经制作了不和谐机器人,只需使用内置的 /giphy <search term> 消息命令,只是一个想法。让我看看新的错误。
    • @RaymondHsu 我在GIPHY Developers website 上找到了这个://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); });
    猜你喜欢
    • 2017-05-28
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2019-12-21
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    相关资源
    最近更新 更多