cmd.user.avatar

Returns the avatar URL of a user. If no ID is provided, returns the avatar of the message author.

JavaScript
const { cmd } = require("syntx.js");

await cmd.user.avatar(id, message, options);

Parameters

ParameterTypeRequiredDescription
idstringNoThe user ID to fetch the avatar for. Defaults to the message author.
messagediscord.js Message | InteractionYesThe message or interaction context.
optionsobjectNoImage options. See options below.

Options

FieldTypeDefaultDescription
formatstring"png"Image format: "png", "jpg", "webp", or "gif" for animated avatars.
sizenumber128Image size in pixels. Must be a power of 2 between 16 and 4096.

Returns

string : The URL of the user's avatar.

Examples

Get the message author's avatar

JavaScript
client.command({
  name: "avatar",
  content: async (message) => {
    const url = await cmd.user.avatar(null, message, { size: 512 });
    message.reply(url);
  },
});

Get another user's avatar

JavaScript
client.command({
  name: "avatar",
  content: async (message) => {
    const id = cmd.message.mentioned(message, 1);
    if (!id) return message.reply("Please mention a user.");

    const url = await cmd.user.avatar(id, message, { size: 1024, format: "webp" });
    message.reply(url);
  },
});