Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda