我想将一个特定的成员(member)信息(用户名 + 头像)添加到嵌入消息中。有人知道该怎么做吗?
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")
在上面的代码中,我想通过特定的不和谐成员标识 ID 更改“message.author.username”和“message.author.avatarUrl”,例如:436577130583949315。
但是我不知道如何从该不一致的标识号中显示用户名和头像。
预先感谢您的帮助:)
最佳答案
由于 Manager 的实现,必须修改以下代码才能使用最新版本的 Discord.js(本次编辑时为 v12)。
您可以通过用户 ID 从客户端的用户缓存中检索用户,Client#users
。但是,不能保证每个用户始终被缓存,因此您可以使用 Client#fetchUser()
从 Discord 获取用户。 。请记住,它返回 Promise 。如果用户位于缓存中,该方法将返回它。
示例:
// Async context needed for 'await'
try {
const devID = '436577130583949315';
const dev = await client.fetchUser(devID);
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);
}
关于javascript - 如何使用discord.js获取特定成员(member)用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56619167/