0

I want to find the user id of the person who DMs the bot. Is there any way to do it? I am using Discord.js I tried by storing member author and member Id but it didn't work. But when I store channel, it store it as authors tag. But the id for that channel does not matches with the id of the user who DM the bot. I am trying to make support mail bot. But it requires the user id so that I can continue the thread by DMing the user. But it's not possible until I get the user id or server member object. And I can't store that DMchannel in my database because i use json for storing datas.

Chaos
  • 1
  • 1
  • 2

2 Answers2

2

Due to my low reputation, I can't comment, sorry if this does not answer your question.

You can get the ID of the person who DM'd your bot by message.author.id (keep in mind, message will need to change to whatever variable your message is stored in).
You can also get the channel ID with message.channel.id.

The channel ID is not the same as the user's ID (they are two different things), which I assumed you misunderstood from id for that channel does not matchs with the id of the user who DM the bot.

java
  • 242
  • 3
  • 9
1

Try this:

const client = new discord.Client();

client.login('token here');

/* On message event since you want to 
 * recieve DM and get ID from user who sent DM to your bot.
 */

client.on("message", (msg) => {

  // checks if the message's channel type is 'DM'.
  if(msg.channel.type === "dm") {

    // you can do anything you want here. In my case I put console.log() function.
    // since you wanted user ID, you can use msg.author.id property here.
    console.log(`Recieved DM from ${msg.author.tag}, DM content is`, msg.content);
  }
});

Please remember, author/member ID and dm message channel ID is completely separate thing.

Also storing member related data in JSON or an SQL is not a really good idea here. I suggest you only doing that for custom data you've generated, or that would be wasting a lot of memory.