I'm trying to create an info
command that pulls the specified users info. As per the discord.js docs, I'm force fetching the specified user to get the .hexAccentColor
. The user I'm fetching does have an accent color, yet I get undefined
as the value every time I try to get it. Here is my code:
const user = await client.users.fetch(
interaction.options.getUser("user"),
false,
true
);
const embed = new MessageEmbed()
.setColor(`${user.hexAccentColor}`)
.setTitle(`User info for ${user.username}`)
.addFields(
{ name: "User Tag:", value: `${user.tag}`, inline: true },
{ name: "User ID:", value: `${user.id}`, inline: true },
{ name: "Bot Status:", value: `${user.bot}`, inline: true },
{
name: "Account Creation Date:",
value: `${user.createdAt}`,
inline: false,
}
)
.setImage(`${user.displayAvatarURL()}`);
All the other information is being passed correctly, it's just the color values that I'm getting undefined
for.
You aren't actually force fetching. The arguments aren't correct (see UserManager#fetch()
). Here's how to force fetch a user
const user = await client.users.fetch(
interaction.options.getUser("user"),
{
force: true
}
)
But rather than fetching like this, you could do a simple User#fetch()
, since interaction.options.getUser
returns a User
instance
const user = await interaction.options.getUser("user").fetch(true)