如何让Discord.js突击队在继续之前等待?

时间:2020-02-07 22:49:25

标签: javascript node.js discord.js

我正试图等待,直到用户发送单个消息以回复机器人。但是,它遍历了我所有的代码,并在此过程中吐出来了:

(node:29808) DeprecationWarning: Collection#filterArray: use Collection#filter instead
(node:29808) UnhandledPromiseRejectionWarning: #<Collection>
(node:29808) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:29808) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我的Discord命令的代码:(类DMallCommand扩展了commando.Command)

async run(message){
        let dmGuild = message.guild;
        let role = message.mentions.roles.first();
        let msg = "";
        let OnlineMembers = [];
        let interest;

        // First we use fetchMembers to make sure all members are cached

        let memberarray = dmGuild.members.array();
        let membercount = memberarray.length;
        let botcount = 0;
        for (var i = 0; i < membercount; i++) {
            let member = memberarray[i];
            if (member.user.bot) {
                botcount++;
                continue
            }
            if (member.presence.status == 'online') {
                OnlineMembers.push(member);
            }
        }

        message.reply('you now have *ten minutes* to send the message that you would like to massDM here.')
        // Await !vote messages
        const filter = m =>  message.author.id === m.author.id;
        // Errors: ['time'] treats ending because of the time limit as an error
        message.channel.awaitMessages(filter, { max: 1, time: 60000, errors: ['time'] })
            .then(collected => msg = collected.content)
            .catch(message.reply('you did not enter any input!'));


        message.reply('you now have *ten minutes* to send the message that you would like to massDM here.').then(() => {
            const filter = m => message.author.id === m.author.id;

            message.channel.awaitMessages(filter, { time: 600000, max: 1, errors: ['time'] })
                .then(messages => {
                    msg = messages.content;
                })
                .catch(() => {
                    message.reply('you did not enter any input!');
                });
        });
        message.author.send(`You are selecting *${OnlineMembers.length}* members, and excluding *${botcount}* bots.`);
        const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, { time: 60000, max: 1, maxMatches: 1 });
        collector.on('collect', message2 => {
            msg = message2.content;
        })
        let wait = 0
        while (msg = "") {
            wait++;
            setTimeout(function(){
                continue
            }, 2000);
        }

我试图编写我想做的事情的多个版本,但没有任何效果。响应是这样的: @ alex-,您现在有十分钟的时间在此处发送您要进行massDM的消息。 @ alex-,您未输入任何输入! @ alex-,您现在有十分钟的时间在此处发送您要进行massDM的消息。 这似乎很简单……我想念什么?

0 个答案:

没有答案