首页 > 解决方案 > Discord.js 收集器问题未更新嵌入

问题描述

我正在尝试获取它,以便我的不和谐机器人将使用用户回复更新嵌入,但是我没有收到任何错误,控制台日志中也没有任何内容。

因此,在我认为问题在于我没有从该代码中获得任何控制台日志的部分。我已经尝试过获得帮助,但我似乎无法找到解决此问题的解决方案。

我将在不和谐聊天(!开始)中发布一个命令,然后机器人将回复 3 个嵌入,然后等待 3 个字母的回复(UUU),然后它意味着用用户的回复更新嵌入但是对于一些未知的原因,我的代码看起来不错,除非 discord.js 不支持某些东西。

完整代码:

const collector = battleChannel.createMessageCollector(filter, {max: 200, maxMatches: 200, time: 180000});
        collector.on('collect', m => {
            console.log(`Collected ${m.content} | ${m.author.username}`);

            if (game.data.length === 0 && m.content.length === 3){
                game.addID(m.content.toUppercase(), m.author.username);
            }else if (m.content.length === 3){
                if (game.userPresent(m.author.username)){
                    game.deleteUserEntry(m.author.username);
                    if (game.idPresent(m.content.toUppercase())){
                        game.addUser(m.content.toUppercase(), m.author.username);
                    }else {
                        game.addID(m.content.toUppercase(), m.author.username);
                    }
                } else {
                   if (game.idPresent(m.content.toUppercase())){
                       game.addUser(message.content.toUppercase(), message.author.username);
                   }else {
                       game.addID(m.content.toUppercase(), m.author.username);
                   }
                }
            }

            game.sort();

            let str = "";
            last3 = new Discord.MessageEmbed()
                .setTitle ("Alliance joined!")
                .setColor ("#0099ff")
                .setTimestamp();

            for (var i = 0; i < game.data.length; i++){
                str = "";
                for (var j = 0; j < game.data[i].users.length; j++){
                    str += game.data[i].users[j] + "\n";
                }
                last3.addField(`${game.data[i].id.toUppercase()} - ${game.data[i].users.length} PLAYERS`, str, true);
            }

            editLast3.edit({embed: last3}).catch((err) => {
                console.log("Caught edit error");
            });

            if (m.deletable){
                m.delete().catch((err) => {
                    console.log("Cannot Delete");
                    console.log(err);
                });

                collector.on('end', collected => {
                    console.log(`Collected ${collected.size} items`);
                });
            }

        });
        
    };

我认为问题出在哪里:

const collector = battleChannel.createMessageCollector(filter, {max: 200, maxMatches: 200, time: 180000});
        
        collector.on('collect', m => {
            console.log(`Collected ${m.content} | ${m.author.username}`);

            if (game.data.length === 0 && m.content.length === 3){
                game.addID(m.content.toUppercase(), m.author.username);
            }else if (m.content.length === 3){
                if (game.userPresent(m.author.username)){
                    game.deleteUserEntry(m.author.username);
                    if (game.idPresent(m.content.toUppercase())){
                        game.addUser(m.content.toUppercase(), m.author.username);
                    }else {
                        game.addID(m.content.toUppercase(), m.author.username);
                    }
                } else {
                   if (game.idPresent(m.content.toUppercase())){
                       game.addUser(message.content.toUppercase(), message.author.username);
                   }else {
                       game.addID(m.content.toUppercase(), m.author.username);
                   }
                }
            }

            game.sort();

            let str = "";
            last3 = new Discord.MessageEmbed()
                .setTitle ("Alliance joined!")
                .setColor ("#0099ff")
                .setTimestamp();

            for (var i = 0; i < game.data.length; i++){
                str = "";
                for (var j = 0; j < game.data[i].users.length; j++){
                    str += game.data[i].users[j] + "\n";
                }
                last3.addField(`${game.data[i].id.toUppercase()} - ${game.data[i].users.length} PLAYERS`, str, true);
            }

            editLast3.edit({embed: last3}).catch((err) => {
                console.log("Caught edit error");
            });

            if (m.deletable){
                m.delete().catch((err) => {
                    console.log("Cannot Delete");
                    console.log(err);
                });

                collector.on('end', collected => {
                    console.log(`Collected ${collected.size} items`);
                });
            }

        });
        
    };

感谢您花时间查看此线程并为我提供帮助。

标签: javascriptnode.jsdiscorddiscord.jsbots

解决方案


推荐阅读