Role
Role wraps a Discord role payload with permission access, color helpers, and mention formatting.
Import
Section titled “Import”import { Role } from "lunibee";import { Role } from "lunibee";Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
id |
string |
Snowflake ID. |
name |
string |
Role name. |
color |
number |
Role color as a 24-bit RGB integer. |
colorHex |
string |
Role color as #RRGGBB hex string. |
hoist |
boolean |
Whether this role is displayed separately in the member list. |
permissions |
PermissionsBitField |
Permission bitfield. |
managed |
boolean |
Whether this role is managed by a bot or integration. |
mentionable |
boolean |
Whether this role can be mentioned. |
position |
number |
Position in the role hierarchy. |
unicodeEmoji |
string | null |
Unicode emoji icon. |
iconHash |
string | null |
Custom icon image hash. |
tags |
Record<string, unknown> | null |
Role tags (bot ID, integration ID, etc.). |
createdAt |
Date |
When the role was created (from snowflake). |
Methods
Section titled “Methods”iconURL(options?)
Section titled “iconURL(options?)”Returns the custom icon URL for this role, or null if none.
const icon = role.iconURL({ size: 64 });const icon = role.iconURL({ size: 64 });isEveryone(guildId)
Section titled “isEveryone(guildId)”Returns true if this is the @everyone base role (role ID equals guild ID).
if (role.isEveryone(guildId)) { console.log("This is the @everyone role.");}if (role.isEveryone(guildId)) { console.log("This is the @everyone role.");}toString()
Section titled “toString()”Returns the Discord role mention string. Used automatically in template literals.
await channel.send({ content: `Welcome! You've been assigned ${role}.` });// → "Welcome! You've been assigned <@&123456789>."await channel.send({ content: `Welcome You've been assigned ${role}.` });// → "Welcome You've been assigned <@&123456789>."Examples
Section titled “Examples”Assign a role on join
client.on("guildMemberAdd", async (memberData) => { const WELCOME_ROLE_ID = "123456789012345678"; const guild = client.guilds.get(memberData.guild_id); if (!guild) return; await client.channels.members(memberData.guild_id).addRole(memberData.user.id, WELCOME_ROLE_ID);});client.on("guildMemberAdd", async (memberData) => { const WELCOME_ROLE_ID = "123456789012345678"; const guild = client.guilds.get(memberData.guild_id); if (!guild) return; await client.channels.members(memberData.guild_id).addRole(memberData.user.id, WELCOME_ROLE_ID);});Role info command
client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "roleinfo") return; const roleData = interaction.options.getRole("role", true) as any; const embed = new EmbedBuilder() .setTitle(roleData.name) .setColor(roleData.color || 0x99aab5) .addFields( { name: "Color", value: `#${roleData.color.toString(16).padStart(6, "0").toUpperCase()}`, inline: true }, { name: "Mentionable", value: roleData.mentionable ? "Yes" : "No", inline: true }, { name: "Hoisted", value: roleData.hoist ? "Yes" : "No", inline: true }, ); await interaction.reply({ embeds: [embed] });});client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "roleinfo") return; const roleData = interaction.options.getRole("role", true) as any; const embed = new EmbedBuilder() .setTitle(roleData.name) .setColor(roleData.color || 0x99aab5) .addFields( { name: "Color", value: `#${roleData.color.toString(16).padStart(6, "0").toUpperCase()}`, inline: true }, { name: "Mentionable", value: roleData.mentionable ? "Yes" : "No", inline: true }, { name: "Hoisted", value: roleData.hoist ? "Yes" : "No", inline: true }, ); await interaction.reply({ embeds: [embed] });});