Hello im programming a discord chat bot, that when the command '!help' is directed to a certain text channel, the bot writes a direct message to the person who wrote the command in order to answer a series of questions, this is the code that I did for now:
const {Client, RichEmbed, Intents, MessageEmbed} = require('discord.js');
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });
const token = 'TOKEN';
const PREFIX = '!';
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}!`);
})
bot.on('messageCreate', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'help':
const Embed = new MessageEmbed()
.setTitle("Helper Embed")
.setColor(0xFF0000)
.setDescription("Make sure to use the !help to get access to the commands");
message.author.send(Embed);
break;
}
});
bot.login(token);
The bot writes to the DM of the user that requested the command, but I have not been able to solve, that according to what the user answers, the robot response with other information, and also that the user can answer with reactions.
If you just want to wait for some messages to come, you can use awaitMessages. It has a few options such as the number of messages to wait for, the time it will collect messages for and an optional filter. An example:
const filter = (message) => {
// Do some validation
}
message.channel.awaitMessages({
time: '', // The time the collector is valid for in milliseconds
max: '', // The number of messages the collector will wait for
filter,
error: ['time'] // Give an error when the timer runs out so the .catch function runs
}).then(collected => console.log(collected)) // Console log all the collected messages
.catch(collected => console.log(`${collected.size} messages were collected`))
But if you are using buttons, then a simple messageComponentCollector will do. Even in this, you have the same options as the awaitMessages such as the time, the maximum number of messages and the filter. Example:
const filter = (click) =. {
// Do some validation
}
const collector = message.channel.createMessageComponentCollector({
time: '', // The time the collector is valid for in milliseconds
max: '', // The number of messages the collector will wait for
filter
})
collector.on('collect', i => console.log(i));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));