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

289
Views
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 answers
Answer question

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 Report

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 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!