首页 > 解决方案 > 当 bot DM 用户收集响应时,消息收集器不会启动

问题描述

因此,这与上一个问题(上一个问题)有关好像消息收集器没有启动?机器人向用户发送消息,控制台中没有任何内容,仅此而已。您可以整天回复机器人,它不会收集并发送到频道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();   
            }

标签: javascriptnode.jsdiscorddiscord.js

解决方案


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

根据文档,您应该这样做:

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 => { 
    // ...
});

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


推荐阅读