2
module.exports = {
    name: 'messageCreate',
    execute(message) {
        if (message.channel.type == 'DM') {
            console.log('Dm recieved')
            client.channels.get('1026279100626767924').send(message);
         }

    }
};

I created event handling by referring to the Discord JS guide. I want my bot to receive a DM and send that message to my admin channel.

But the bot is not recognizing the DM What should I do

(I'm using a translator)

Gamby1223
  • 23
  • 1
  • 3

3 Answers3

6

You need to include partials Channel and Messages configurations on creating client:

const client = new Client({
  intents: [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.MessageContent
  ],
  partials: [
    Partials.Channel,
    Partials.Message
  ]
})

That solved it for me!

2

You can use messageCreate event for listening your bot's DMs.

client.on("messageCreate", async message => {
    if (message.guild) return;
    console.log(`Someone sent DM to me => ${message.content}`);
    await client.channels.cache.get(CHANNEL_ID).send(messsage.content);
});
Alpha
  • 172
  • 1
  • 6
1

There could be a couple problems with this. First off, it could be your Intents.

Intents allow your bot to process certain events. The intents that you will want are: DirectMessages MessageContent (this one may not be required, I am unsure).

So, go to where you initialize your client. It should look something like this:

const Discord = require("discord.js");
const client = new Discord.Client();

and change it into this:

const Discord = require("discord.js");
const { GatewayIntentBits, Client } = Discord;

const client = new Client({
  intents: [
    GatewayIntentBits.DirectMessages
    GatewayIntentBits.MessageContent

  ]
});

The second issue could be that your message handler isn't detecting it properly. Like the other answer says, you should just determine if there is no Guild attached to the message.

client.on("messageCreate", async(message) => {
  if(!message.guild) {
   client.channels.cache.get("YOUR_ID").send(message);
  }
});

There could be other issues, but those two are the most probable. Considering you're not getting any errors, I'd presume it's the first one, the issue with Intents.

Hope this helps!

Connor
  • 58
  • 3