Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
Bot de Discord que responde a un mensaje directo

Estoy usando discord.js y estoy tratando de hacer que si un usuario envía un mensaje directo a un bot, responderá una respuesta simple como "Lo siento, no puede enviarme un mensaje privado. Utilice el sistema de tickets". en cambio."

Intenté usar:

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

Esto no produce resultados.

Soy totalmente nuevo en la codificación y agradecería la ayuda.

Gracias

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

OK, ahora resolví esto para siempre.

Estaba perdido:

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

(utilicé esta guía: https://github.com/discordjs/discord.js/issues/5516#issuecomment-985458524 )

Para la respuesta:

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

Debí haber usado DM MAYÚSCULAS, Jesucristo. Ahora funciona como un encanto!

Gracias a todos.

about 4 years ago · Juan Pablo Isaza Report

0

Está utilizando el evento de mensaje, por lo que necesita un comando para funcionar.

if (message.content === "test") , su comando está en la Cadena.

if (message.channel.type === "dm") , y esto detecta en qué tipo de canal está el usuario para usar el comando.

return message.reply("") , luego enviará un mensaje de error en el dm del usuario porque el comando no se puede ejecutar en dm's.

de else , si no detecta un canal dm, ignorará la respuesta de error.

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!