I’m new to creating Discord bots and I’m stuck on a problem. I want my bot to pause and wait for my message before moving on. But I can’t figure out how to make this work.
Here’s what I’m trying to do:
- Bot asks a question
- Bot waits for my answer
- Bot continues based on my input
I’ve tried using awaitMessages(), but it’s not working as expected. The bot just keeps going without waiting for my response.
Here’s a simplified version of my code:
const Discord = require('discord.js');
class GameSetup extends Command {
async execute(client, message, args) {
if (!message.member.hasRole('gamemaster')) {
return message.reply('Only gamemasters can set up games!');
}
message.channel.send('Choose a map:');
message.channel.send('1. Dustbowl\n2. 2Fort\n3. Badlands');
// This part doesn't work as intended
const response = await message.channel.awaitMessages(
m => m.author.id === message.author.id,
{ max: 1, time: 30000 }
);
// Bot should wait here, but it doesn't
message.channel.send('Thanks for your choice!');
}
}
Can someone help me understand what I’m doing wrong? How can I make the bot actually wait for my input before moving on?
I encountered a similar challenge when developing my Discord bot. The issue likely stems from how you’re handling the promise returned by awaitMessages(). Try this approach:
try {
const collected = await message.channel.awaitMessages({
filter: m => m.author.id === message.author.id,
max: 1,
time: 30000,
errors: ['time']
});
const response = collected.first().content;
message.channel.send(`You chose: ${response}`);
} catch (error) {
message.channel.send('No response received. Setup cancelled.');
}
This structure ensures the bot waits for your input before proceeding. The filter targets your specific user ID, and the error handling manages timeouts gracefully. Remember to adjust the timeout duration as needed for your use case.
hey there! i’ve had similar issues before. try using a filter function with awaitMessages() to make sure it only listens for your specific input. also, wrap the whole thing in a try/catch block to handle timeouts. that should do the trick! lemme know if u need more help 
As someone who’s been in the Discord bot dev trenches, I feel your pain. Here’s a trick that worked wonders for me:
Instead of relying solely on awaitMessages(), I found using a message collector to be more reliable. It gives you finer control over the waiting process. Here’s a quick example:
const filter = m => m.author.id === message.author.id;
const collector = message.channel.createMessageCollector({ filter, time: 30000 });
collector.on(‘collect’, m => {
console.log(Collected ${m.content});
collector.stop();
});
collector.on(‘end’, collected => {
if (collected.size === 0) {
message.channel.send(‘No response received. Try again?’);
} else {
message.channel.send(You chose: ${collected.first().content});
}
});
This approach gives you more flexibility and better error handling. Plus, it’s easier to debug if something goes wrong. Give it a shot and see if it helps!