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

269
Visualizações
Collecting input through DMs

I'm wondering if it's even possible to get user's input through DMs after calling a slash command. I've created a little mini-game that would ideally be played in the user's DMs to avoid spamming the channel it was called in. An example of my code structure is as followed:

module.exports = {
    data: new SlashCommandBuilder()
    .setName('game')
    .setDescription('Play game'),
async execute(interaction) {
    const score = await gameLogic(interaction.user);
    await interaction.reply(score);
    },
};

Then I send the user a DM letting them know that the game has started and call a function that will wait for the user input.

async function gameLogic(user) {
    user.send("Game time");
    let userInput = getUserInput();
    .... game logic ...
}

I've tried using message collectors and awaitMessage but can't seem to get it working. Really trying to exhaust all options until moving on to a different solution.

I appreciate any advice!

EDIT Unfortunately I don't remember exactly what I've tried but I can give some examples.

My message collector was something along the lines of this:

async function getUserInput() {

    console.log("Awaiting user input");

    const filter = message => message.author.id === m_user.id;
    const collector = m_interaction.channel.createMessageCollector({ filter, max: 1, time: 15000, errors: ['time'] })
    collector.on('collect', message => console.log(`You wrote ${message.content}`));
    collector.on('error', collected => console.log("Time out"));
} 

And my awaitMessage was something like this:

async function getUserInput() {
    const filter = message => message.author.id === m_user.id;
    const message = await m_interaction.channel.awaitMessages({ filter, max: 1, time: 15000, errors: ['time'] })
        .then(message => m_interaction.channel.send(`You wrote ${message.content}`))
        .catch(collected => m_interaction.channel.send("Time out"));

    console.log(message);
}

I'm sure these will work for collecting input from the channel the command was called in, but I'm not sure how I could alter them to collect input through the DMs. I did read a little into dmChannel but couldn't seem to get it working the way I wanted it to.

EDIT 2 + SOLUTION I've managed to store the DMChannel with the user by using.

const channel = user.createDM();

And I can now use the MessageCollector there. Hopefully this helps.

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

0

I've managed to store the DMChannel with the user by using.

const channel = user.createDM();

And I can now use the MessageCollector there. Hopefully this helps.

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