Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
How to read user content DiscordBot in Javascript

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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`));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda