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

291
Visualizações
Discord bot that replys to a direct message

I'm using discord.js and I'm trying to make if a user sends a direct message to a bot, it will respond a simple reply such as "I'm sorry, You can not DM me. Please use the ticket system instead."

I tried using:

client.on('message', msg => {
  if (msg.channel.type == "dm") {
    msg.author.send(" blah blah example text");
    return;
  }
});

This yields no results.

I'm totally new to coding and I would appreciate the help.

Thanks

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

0

OK, now I solved this for good.

I was missing:

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES", "DIRECT_MESSAGE_REACTIONS", "DIRECT_MESSAGE_TYPING"], partials: ['CHANNEL',] })

(used this guide: https://github.com/discordjs/discord.js/issues/5516#issuecomment-985458524)

For the reply:

  if (message.channel.type === "DM") {
     return message.reply({ content: "TEXT" });
   }

I should've used CAPITAL DM, Jesus Christ. Now it works like a charm.

Thanks everybody.

about 4 years ago · Juan Pablo Isaza Relatório

0

Your using the message event, so it needs a command to function.

if (message.content === "test"), your command is in the String.

if (message.channel.type === "dm"), and this detects what channel type is the user in for using the command.

return message.reply(""), then it will send an error message in the user's dm because the command cannot be executed in dm's.

else, if it doesn't detect a dm channel then it will ignore the error response.

client.on("message", message => {
  if (message.content === "test") {
    if (message.channel.type === "dm") {
      return message.reply({ content: "This message is a dm for the user." });
    } else {
      return message.reply({ content: "This message is a message sent to channel." });
    }
  }
});
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