问题
I would like to add one specific member information (username + avatar) into an embed message. Does someone know how to do that?
const feedback = new discord.RichEmbed()
.setColor([0, 0, 255])
.setFooter("Bot created by : " + message.author.username, message.author.avatarURL)
.setDescription("The text I want to be sent")
On the code above, I would like to change "message.author.username" and "message.author.avatarUrl" by a specific discord member identification id such as : 436577130583949315 for example.
However I don't know what is the way from that discord identification number to be able to show the username and the avatar.
Thanks in advance for your help :)
回答1:
You can retrieve a user by their ID from the client's cache of users, Client.users. However, every user isn't guaranteed to be cached at all times, so you can fetch a user from Discord using Client.fetchUser(). Keep in mind, it returns a Promise.
Example:
// Async context needed for 'await'
try {
const devID = '436577130583949315';
const dev = client.users.get(devID) || await client.fetchUser(devID);
// Retrieve the user from the client's cache.
// If they haven't been cached yet, fetch them.
const feedback = new discord.RichEmbed()
.setColor([0, 0, 255])
.setFooter(`Bot created by ${dev.tag}.`, dev.displayAvatarURL)
.setDescription('Your text here.');
await message.channel.send(feedback);
} catch(err) {
console.error(err);
}
来源:https://stackoverflow.com/questions/56619167/how-to-get-specific-member-username-with-discord-js