如何使用 discord.js 获取特定的会员用户名

How to get specific member username with discord.js(如何使用 discord.js 获取特定的会员用户名)
本文介绍了如何使用 discord.js 获取特定的会员用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在嵌入消息中添加一个特定的成员信息(用户名 + 头像).有人知道怎么做吗?

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 获取特定的会员用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)