不和谐收集器无法收集DM

时间:2019-08-21 16:21:30

标签: javascript bots discord.js

当我尝试使用Discord消息收集器时,我无法在discord.js中收集DM

我尝试将“ message.channel”更改为message.author,但无法正常工作

const collector = new discord.MessageCollector(message.channel, m => m.author.id === message.author.id, { time: 30000 });
        collector.on('collect', message => {
            if (message.content == strng) {
                message.channel.send(`Successfully Verified User: <@${message.author.id}>`).then(m => {
                    m.delete(30000)
                    message.member.addRole('470615991555063808')
                }).catch(err => console.log(err));
            }
        })

预期:具有正确字符串的用户DM机器人,并对其进行验证

实际:用户必须将字符串与用户最初所说的!verify放在同一频道中

2 个答案:

答案 0 :(得分:0)

用户必须将字符串放在同一通道中,因为您正在使用message.channel作为第一个MessageCollector参数收集该通道中的消息。 相反,您可以做的是与用户打开一个DMChannel,并用.then()将其返回,如下所示:

 message.author.createDM().then(dmchannel => {
 const collector = new discord.MessageCollector(dmchannel, m => m.author.id === message.author.id, { time: 30000 });
   collector.on('collect', m => {
     if (m.content == strng) {
       message.channel.send(`Successfully Verified User: <@${message.author.id}>`)
      .then(m => {
         m.delete(30000)
          message.member.addRole('470615991555063808')}).catch(err => console.log(err))}
         })
    })

答案 1 :(得分:-1)

我已经解决了...

我用过

message.author.createDM().then(c => {
            var verified = new discord.RichEmbed()
                .setTitle("Verification Started")
                .addField("**User**", `${message.author}`, false)
                .setFooter("Goriko Bot")
                .setColor(0xfffb00)
                .setTimestamp();
            message.guild.channels.get('470619175547830315').send(verified).catch(err => console.log(err));
            console.log("DM Created")
            c.send(verifyEmbed)
            console.log(`Embed Sent to ${message.author.tag}`)
            const filter = m => m.content.includes("~");
            const collector = c.createMessageCollector(filter, { time: 30000 })
            console.log("Collector Created")
            collector.on('collect', m => {
                console.log('Reply Collected')
                if (m.content === strng) {
                    console.log('Success')
                    c.send("Successfully Verified")
                    if (message.channel.type == "dm") return;
                    message.member.addRole('470615991555063808').catch(err => console.log(err));
                    var successEmbed = new discord.RichEmbed()
                        .setTitle("Verification Successful")
                        .addField("**User**", `${message.author}`, true)
                        .addField("**String**", `\`\`${strng}\`\``, true)
                        .setFooter("Goriko Bot")
                        .setColor(0x00ff00)
                        .setTimestamp();
                    message.guild.channels.get('470619175547830315').send(successEmbed).catch(err => console.log(err));
                } else {
                    var failEmbed = new discord.RichEmbed()
                        .setTitle("Verification Failed")
                        .addField("**User:**", `${message.author}`, true)
                        .addField("**Correct Token:**", `${strng}`, true)
                        .addField("**Token Given:**", `${m.content}`, true)
                        .setColor(0xff0000)
                        .setFooter("Goriko Bot")
                        .setTimestamp();

                    message.guild.channels.get('470619175547830315').send(failEmbed).catch(err => console.log(err));
                    m.reply("Invalid Token! Please Try Again")
                }
            })
        })