Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  137] [ 4]  / answers: 1 / hits: 6227  / 4 Years ago, thu, september 3, 2020, 12:00:00

I have a bot that takes a mention and returns some user information:


bot.on('message', async message => {
let usr = bot.users.fetch(message.replace('<@!', '').replace('>', ''));
message.channel.send(`id: ${usr.id}nname: ${usr.username}`);
});

However, the bot returns undefined for both values. I have logged the user object, and revieved


Promise {
User {
id: '',
username: '',
bot: false,
discriminator: '',
avatar: '',
lastMessageId: '',
LastMessage: '',
}
}

The values are different, but the objects are the same. I tried using usr.Promise.User.value, usr.User.value, and usr.Promise.value with no luck. Is there some way to do this?


More From » discord

 Answers
9

You can also use message.mentions.users.first():


bot.on('message', async message => {
let usr = message.mentions.users.first();
message.channel.send(`id: ${usr.id}nname: ${usr.username}`);
});

It's a totally different way to do what you want and it's better. It also avoids your "promise" problem so it's not really an answer.


[#2744] Monday, August 31, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminuniquer

Total Points: 63
Total Questions: 121
Total Answers: 96

Location: Cambodia
Member since Thu, May 21, 2020
4 Years ago
;