Skip to content

User

User wraps a Discord user object, providing display name resolution, avatar URL helpers, and automatic mention formatting in template literals.

import { User } from "lunibee";
Property Type Description
id string Snowflake ID.
username string Discord username (unique handle).
globalName string | null Display name set by the user.
avatar string | null Avatar hash. Use avatarURL() for the full URL.
discriminator string | null Legacy #XXXX tag, or null for new username system users.
bot boolean Whether this user is a bot account.
system boolean Whether this is an official Discord System account.
flags number Public user flags bitfield.
displayName string Global name if set, otherwise username.
createdAt Date Account creation timestamp from snowflake.
createdTimestamp number The same, in milliseconds since the Unix epoch.

Returns the user’s avatar URL, or null if they have no avatar. The extension defaults to gif for an animated (a_) hash and png otherwise; forceStatic turns the animated default into png.

const url = user.avatarURL({ size: 256 });
// → "https://cdn.discordapp.com/avatars/123/abc.png?size=256"

Options:

interface ImageURLOptions {
extension?: "png" | "jpg" | "webp" | "gif" | "jpeg";
size?: 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
forceStatic?: boolean; // prevent animated GIFs
}

Returns the default avatar URL based on the user’s discriminator or snowflake.

const fallback = user.defaultAvatarURL();

Returns the avatar URL if one is set, otherwise the default avatar URL. Always returns a string.

const avatar = user.displayAvatarURL({ size: 128 });

Returns the Discord user mention string. Used automatically in template literals.

console.log(`Hello ${user}!`); // → "Hello <@123456789>!"

User info embed

import { CreateEmbed, User } from "lunibee";
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "whois") return;
// getUser() returns Discord's raw user data; wrap it in User for the helpers.
const picked = interaction.options.getUser("user");
const target = picked ? new User(picked) : interaction.user;
if (!target) return;
const embed = new CreateEmbed()
.setTitle(target.displayName)
.setThumbnail(target.displayAvatarURL({ size: 256 }))
.addFields(
{ name: "Username", value: target.username, inline: true },
{ name: "ID", value: target.id, inline: true },
{ name: "Bot", value: target.bot ? "Yes" : "No", inline: true },
{ name: "Account Created", value: `<t:${Math.floor(target.createdAt.getTime() / 1000)}:R>`, inline: true },
)
.setColor(0x5865f2);
await interaction.reply({ embeds: [embed] });
});

Mention a user in a message

client.on("messageCreate", async (message) => {
if (message.content === "!me") {
await message.reply(`You are ${message.author} — ID: \`${message.author.id}\``);
}
});