首页 > 解决方案 > 帮助寻找朋友机器人

问题描述

我的朋友有一个名为 Find A Friend 的不和谐服务器,他希望我编写一个机器人来输入命令来提出一系列问题并将其放入频道中。人们可以看到是否有人对他们感兴趣并与他们成为朋友。我已经编码了它的一部分。

它提出的问题之一是:你喜欢什么游戏?

我的朋友希望机器人能够搜索同一问题的其他答案,如果他们有共同的游戏,请通知用户。我想对另一个问题做同样的事情:你喜欢哪些节目、电影和动漫?

这是我的一系列问题的代码:

const { Client, Message, MessageEmbed } = require("discord.js")

module.exports = {
    name: "faf",
    /**
     * @param {Client} client
     * @param {Message} message
     * @param {String[]} args
     */
    run: async (client, message, args) => {
        message.delete()
        const questions = [
            "What is your usernames for any games you have including discord (is fine if you dont put them all but you MUST include your discord)",
            "What is your age (not required)",
            "What is your gender",
            "Do you talk in Voicechannel or through text?",
            "What games do you like?",
            "What are some shows, movies, and anime that you like",
            "Where are you from (not required)",
            "Please state anything else you want to say"

        ]

        let collectCounter = 0;
        let endCounter = 0;

        const filter = (m) => m.author.id === message.author.id;

        const appStart = await message.author.send(questions[collectCounter++]);
        const channel = appStart.channel;

        const collector = channel.createMessageCollector(filter);

        collector.on("collect", () => {
           if(collectCounter < questions.length)  {
               channel.send(questions[collectCounter++])
           } else {
               channel.send('Your Find A Friend thread has been sent, Good Luck!')
               collector.stop("fulfilled");
           }
        });

        const appsChannel = client.channels.cache.get("831292911437086760");
        collector.on('end', (collected, reason) => {
            if(reason === 'fulfilled') {
                let index = 1;
                const mappedResponses = collected
                .map((msg) => {
                    return `${index++}) ${questions[endCounter++]}\n-> ${msg.content}`;
                }).join('\n\n')

                appsChannel.send(
                    new MessageEmbed()
                    .setAuthor(
                        message.author.tag, 
                        message.author.displayAvatarURL({ dynamic: true })
                    )
                    .setTitle('Friend Thread')
                    .setDescription(mappedResponses)
                    .setColor('RED')
                    .setTimestamp()
                )
            }

        });
    },
};

TL;DR 我目前有一个消息收集器机器人,用于记录对问题的响应。我如何让机器人根据他们的反应识别出两个人是否有共同的兴趣,例如游戏、电影、节目或动漫?

标签: node.jsvisual-studio-codediscord.js

解决方案


推荐阅读