問題描述
我想在嵌入消息中添加一個特定的成員信息(用戶名 + 頭像).有人知道怎么做嗎?
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")
在上面的代碼中,我想通過特定的不和諧成員標識 id 更改message.author.username"和message.author.avatarUrl",例如:436577130583949315.
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.
提前感謝您的幫助:)
推薦答案
由于管理器的實現,必須修改以下代碼以使用最新版本的 Discord.js(本次編輯時為 v12).
您可以通過用戶的 ID 從客戶端的用戶緩存中檢索用戶,Client#users
.但是,不能保證每個用戶都始終被緩存,因此您可以使用 Client#fetchUser()
.請記住,它返回一個 Promise.如果用戶在在緩存中,該方法將返回它.
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. If the user is in the cache, the method will return it.
例子:
// 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);
}
這篇關于如何使用 discord.js 獲取特定的會員用戶名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!