Skip to content
Advertisement

How to make discord bot wait for reply for 5 minutes and then send a message? Using discord js

I am using Discord js to make a discord bot. The role of the bot is to send a message to user in personal messages and then wait for user response for 5 minutes. If user does not sends anything back to the member then a message is send by the bot that there request has been denied because they did not send any email id. I am using discord.js collector npm package for taking message and sending it to the user. The problem I am getting is that the bot send back a reply to the user just after 30 seconds if user does not types anything. I don’t want that. I wish the bot to wait for 5 mins before sending request denied message. Here is what my code looks like.

 message.reply("Please check your DM to verify your email id");
                const filter = (m) => m.author.id === message.author.id;
                
                    const botMessage = await message.author.send("Enter your registered email Id please?");
                    const userMessage = await MessageCollector.asyncQuestion({
                      botMessage,
                      user: message.author.id,
                      time:300000 // milliseconds
                    }).catch(()=>{
                      message.author.send("Request Denied because you did not responded with a registerd email ID. You can request again!");
                      return 0;
                    }); 
                    

I have also used discord js library to implement there own parameters such as idle but I am still getting the error. Here is what my code looks there.

message.reply("Please check your DM to verify your email id");
                    const filter = (m) => m.author.id === message.author.id;
                    
                        const botMessage = await message.author.send("Enter your registered email Id please?");
                        const userMessage = await MessageCollector.asyncQuestion({
                          botMessage,
                          user: message.author.id,
                          idle:300000 // milliseconds
                        }).catch(()=>{
                          message.author.send("Request Denied because you did not responded with a registerd email ID. You can request again!");
                          return 0;
                        }); 
                  

Would be great if someone could tell me where I am making a mistake.

Advertisement

Answer

The asyncQuestion function you’re using doesn’t have the time or idle properties. Instead it has the collectorOptions which type is MessageCollectorOptions.

So what you should do is use the collectorOptions that the asyncQuestion defined and pass in an object with your time option, then your timer should work as intended.

const userMessage = await MessageCollector.asyncQuestion({
                    botMessage,
                    user: message.author.id,
                    collectorOptions: { time: 300000 }
                }).catch(() => {
                    // catch code here...
                });
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement