Home > Back-end >  How to get other member discord id?
How to get other member discord id?

Time:06-12

i want to make command that can give me information about someone that i mention like !info @Someone i try code below, but didnt work.

This is the schema

const mongoose = require('mongoose');

const Schema = mongoose.Schema;
const profileSchema = new Schema({
    _id: mongoose.Schema.Types.ObjectId,
    userID: String,
    nickname: String,
    ar: Number,
    server: String,
    uid: Number,
});

module.exports = mongoose.model("User", profileSchema);

and this is what i try, but show nothing, didnt show any error sign.

client.on("message", async msg => {
  let member = msg.mentions.users.first().username
  if (msg.content === `!info @${member}`){ 
    userData = await User.findOne({userID : msg.mentions.users.first().id});
     if (userData) {
        const exampleEmbed = new MessageEmbed()
        .setColor('#808080')
        .setTitle('Data Member')
        .setDescription(`**Nickname :** ${userData.nickname}\n**Adventure Rank :** ${userData.ar}\nServer: ${userData.server}\n**User ID :** ${userData.uid}`)
        .setThumbnail(msg.author.avatarURL())
        msg.reply({ embeds: [exampleEmbed] });
     } else{
      msg.reply("Please registration first")
     }
  }
}
);

CodePudding user response:

Going through your code, I found these errors.

first of all you need members not users in message.mentions.members.first().

Second of all, you need to define UserData first like const UserData = ...

client.on("message", async msg => {
  let member = msg.mentions.members.first().username
  if (msg.content === `!info @${member}`){ 
    User.findOne({userID : member.id}, async (err, userData) => {
     if (userData) {
        const exampleEmbed = new MessageEmbed()
        .setColor('#808080')
        .setTitle('Data Member')
        .setDescription(`**Nickname :** ${userData.nickname}\n**Adventure Rank :** ${userData.ar}\nServer: ${userData.server}\n**User ID :** ${userData.uid}`)
        .setThumbnail(msg.author.avatarURL())
        msg.reply({ embeds: [exampleEmbed] });
     } else{
      msg.reply("Please registration first")
     }
  }
 });
});

Let me know if it works after fixing these errors. Also message event is depricated so try using MessageCreate instead from now on

CodePudding user response:

GuildMember has no 'username' as a property. Use const member = msg.mentions.members.first() and member.user.username instead. For example:

const member = msg.mentions.members.first();
if (msg.content === `!info @${member.user.username}`){ 
    User.findOne({ userID: member.id }, (err, user) => {
        if (err) return console.error(err);
        if (!user) return msg.reply("User not found");
        console.log(user);
        msg.reply(`${user.nickname}`);
    });
}
  • Related