简体   繁体   English

Discord.js 消息收集器无法正常工作,有人可以推荐其他方法来收集消息或如何使它工作吗?

[英]Discord.js Message Collector not working properly, can someone recommend an other way to collect messages or how to make this work?

I made a discord bot using discord.js. This bot should ask questions about a game when someone uses.rank [rank name] and if the user answers correctly he/she receives the rank, I found a way to collect messages, but this method does not want to work, it send the message multiple times and also ignores the time given to the collector, I tried multiple things but neither of them worked?我使用 discord.js 制作了一个 discord 机器人。这个机器人应该在有人使用时询问有关游戏的问题。rank [rank name] 如果用户回答正确,他/她会收到排名,我找到了一种收集消息的方法,但这种方法确实不想工作,它多次发送消息并且也忽略了给收集器的时间,我尝试了多种方法但都没有用? I am very new to creating discord bots so can someone recommend me any other solution to make this bot work?我对创建 discord 机器人还很陌生,所以有人可以向我推荐任何其他解决方案来让这个机器人工作吗?

CODE:代码:

    client.on('messageCreate', message => {
    if (message.content == '!rank r6') {
        message.channel.send('Is Frost an attacker?')
        const collector = new Discord.MessageCollector(message.channel, m => m.author.id == message.author.id, {max: 1, time: 8000})
        collector.on('collect', message => {
                if (message.content == 'no'){
                    message.channel.send('Role added')
                    message.member.roles.add('775660517053562900')
                }
         })
        }     
})

在此处输入图像描述

I'm not sure how you formatted your code to look like that, as the official docs & guide suggest different ways of implementing Collectors.我不确定您是如何将代码格式化成那样的,因为官方文档和指南建议了实现收集器的不同方法。 I personally suggest following the guides carefully.我个人建议仔细遵循指南。

Specifically I see that you try making a new Discord.MessageCollector whereas the guide suggests using a function on message.channel to instate a message collector.具体来说,我看到您尝试制作一个new Discord.MessageCollector ,而指南建议在message.channel上使用 function 来设置消息收集器。

Here are some resources to help you out (assuming you're using Discord.js v12): https://v12.discordjs.guide/popular-topics/collectors.html#message-collectors https://v12.discordjs.guide/additional-info/async-await.html#how-do-promises-work这里有一些资源可以帮助您(假设您使用的是 Discord.js v12): https://v12.discordjs.guide/popular-topics/collectors.html#message-collectors https://v12.discordjs.guide/additional -info/async-await.html#how-do-promises-work

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM