【问题标题】:Message Collector doesn't start when bot DMs user to collect response当 bot DM 用户收集响应时,消息收集器不会启动
【发布时间】:2020-11-05 02:45:21
【问题描述】:

所以这与上一个问题有关,该问题已得到回答(上一个)每当有人运行命令时,机器人不再吐出很多错误,并且机器人成功地向用户发送响应提示,但似乎消息收集器没有启动?机器人向用户发送消息,控制台中没有任何内容,仅此而已。您可以整天回复机器人,它不会收集并发送到频道ID。有什么指点吗?

这是我认为它可能围绕的代码:

        collector.on('collect', (message, col) => {
            console.log("Collected message: " + message.content);
            counter++; ```




And here is all of the code (just in case it actually doesn't revolve around that):
``` if(message.content.toLowerCase() === '&reserveupdate') {
        
        message.author.send('**Thanks for updating us on the reserve. Please enter what you are taking from the reserve below this message:**');
        let filter = m => !m.author.bot;
        let counter = 0;
        let collector = new discord.MessageCollector(message.author, m => m.author.id, filter);
        let destination = client.channels.cache.get('my channel id');
        collector.on('collect', (message, col) => {
            console.log("Collected message: " + message.content);
            counter++;
            if(counter === 1) {
               message.author.send("**Thanks for updating us on the reserve, it is highly appreciated.**");
                collector.stop();   
            }

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    我认为您创建消息收集器的方式可能是错误的。

    根据the docs,你应该这样:

    const filter = m => !m.author.bot;
    
    // If you are in an async function :
    const channel = await message.author.createDM();
    // Paste code here
    
    // Otherwise :
    message.author.createDM.then(channel => {
        // Paste code here
    });
    
    
    // Code to paste :
    const collector = channel.createMessageCollector(filter, { max: 1, time: 60000 });
    collector.on('collect', msg => { 
        // ...
    });
    

    希望这能帮助您解决问题! :)

    【讨论】:

    • 所以,这里有 2 个问题。我试过你上面给出的代码,但没有用。当有人运行 &reserveupdate 时,它​​仍然会 dms 用户,但控制台显示: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'createMessageCollector' of null 然后我删除了 'createMessageCollector' 中的 'Create' 并且它仍然给出相同的类型错误。我打算玩几分钟,看看会不会改变它。
    • 将“成本收集器”更改为“让收集器”,现在它在类型错误中吐出 undefined 而不是 null
    • 抱歉,刚吃完午饭回来。我现在要测试它。
    • 这工作完美无缺,谢谢@tenclea 现在我不再需要处理发送到不和谐频道的无用消息!已标记答案,也已回答。
    猜你喜欢
    • 2019-11-25
    • 2021-03-31
    • 2021-12-31
    • 2019-12-26
    • 2021-10-17
    • 2021-12-11
    • 1970-01-01
    • 2021-04-20
    • 2022-01-21
    相关资源
    最近更新 更多