首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >男高音API搜索不同结果

男高音API搜索不同结果
EN

Stack Overflow用户
提问于 2021-10-06 19:08:32
回答 1查看 259关注 0票数 2

我在制造一个不和谐的机器人。目前,如果您输入-gif **arguments**,它将使用Tenor,并在消息中发布gif的结果,该消息当前运行良好,但它总是给出相同搜索查询的相同结果。我的代码如下所示,那么我将如何使其能够使用相同的查询更改搜索的搜索结果?

代码语言:javascript
复制
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);
    },
};
EN

回答 1

Stack Overflow用户

发布于 2022-04-25 11:04:10

代码语言:javascript
复制
    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);
}

请求10个响应,从传入的响应中随机选择一个,并在message.channel.send部分中使用它!注:已试,有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69471407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档