How to get user id of a member in discord using javascript?

60 Views Asked by At

I have a discord server, i used tatsu bot to allow points members of my server based on how active they are. For that tatsu provides an api : https://dev.tatsu.gg/api/guilds#get-guild-member-points. But for that we need to get the member's discord id. How can i get the discord id of a member using javascript??

1

There are 1 best solutions below

1
GFT On

You can try the following:

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

const TOKEN = 'YOUR_BOT_TOKEN';

client.once('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
});

client.on('message', (message) => {
  if (message.content.startsWith('!getid')) {
    const member = message.mentions.members.first(); // Get the first mentioned member
    
    if (member) {
      message.channel.send(`The Discord ID of ${member.user.username} is: ${member.id}`);
    } else {
      message.channel.send('Please mention a member to get their ID.');
    }
  }
});

client.login(your_token);