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, I am very new to creating discord bots so can someone recommend me any other solution to make this bot work?
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.
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