Skip to main content

User

Representation of a Fluxer user. Stored in the client.users cache.

Fields

FieldTypeDescription
idSnowflakeUnique user identifier.
usernameStringUsername.
discriminatorStringDiscriminator (e.g. "0" if unused).
global_nameOption<String>Display name. Takes precedence over username when set.
avatarOption<String>Avatar hash. None if using the default avatar.
botbooltrue if the account is a bot.
avatar_colorOption<u32>Default avatar color (RGB integer).
flagsOption<u32>Account bitfield flags (public).
systembooltrue for Fluxer system accounts.
bannerOption<String>Profile banner hash.

Constructors

User::from_api

pub fn from_api(data: &ApiUser) -> Self
Creates a User from an API response. flags is taken from flags or public_flags - whichever is non-empty first.

User::unknown

pub fn unknown() -> Self
Returns a stub with username = "Unknown" and an empty id. Use when user data is unavailable.

Methods

display_name

pub fn display_name(&self) -> &str
Returns global_name if set, otherwise username.

mention

pub fn mention(&self) -> String
Returns the mention string in the format <@id>. The Display trait is implemented identically.

avatar_url

pub fn avatar_url(&self, opts: &CdnOptions) -> Option<String>
Returns the user’s avatar URL. None if avatar is None. URL format: https://fluxerusercontent.com/avatars/{user_id}/{hash}.{ext}. For animated avatars (hash starts with a_) the extension is automatically set to gif.

display_avatar_url

pub fn display_avatar_url(&self, opts: &CdnOptions) -> String
Same as avatar_url, but falls back to the default avatar URL (https://fluxerstatic.com/avatars/{index}.png) instead of returning None.
pub fn banner_url(&self, opts: &CdnOptions) -> Option<String>
Returns the profile banner URL. None if banner is None.

create_dm

pub async fn create_dm(&self, rest: &Rest) -> crate::Result<ApiChannel>
Opens a DM channel with the user. If the channel already exists, it is returned without creating a new one.
let dm_channel = user.create_dm(&rest).await?;

let payload = MessagePayload::new()
    .content("Hey, this is a DM!")
    .build();

let route = fluxer_types::Routes::channel_messages(&dm_channel.id);
let _: serde_json::Value = rest.post(&route, Some(&payload)).await?;

patch

pub fn patch(&mut self, data: &ApiUser)
Updates User fields with data from the API. Called automatically by the client on USER_UPDATE and when a cached user is encountered again.

GuildMember

Representation of a guild member. Stored in the client.members[guild_id][user_id] cache.

Fields

FieldTypeDescription
userUserUser data.
guild_idSnowflakeID of the guild this member belongs to.
nickOption<String>Member’s guild nickname. None if not set.
rolesVec<Snowflake>List of role IDs the member has.
joined_atOption<String>Date the member joined the guild (ISO 8601).
premium_sinceOption<String>Date the member started boosting the guild. None if not boosting.
deafboolWhether the member is server-deafened in a voice channel.
muteboolWhether the member is server-muted in a voice channel.
pendingOption<bool>Whether the member has passed the membership screening.
communication_disabled_untilOption<String>Timeout expiry date. None if no active timeout.

Constructors

GuildMember::from_api

pub fn from_api(data: &ApiGuildMember, guild_id: &str) -> Self
Creates a GuildMember from an API response and a guild ID.

Methods

display_name

pub fn display_name(&self) -> &str
Returns nick if set, otherwise user.display_name().

mention

pub fn mention(&self) -> String
Returns the member mention string in the format <@user_id>.

has_role

pub fn has_role(&self, role_id: &str) -> bool
Returns true if the role ID is in roles.

timeout_active

pub fn timeout_active(&self) -> bool
Returns true if communication_disabled_until is set and the date has not yet passed.
if let DispatchEvent::GuildMemberAdd { member } = event {
    println!(
        "Joined: {} (nick: {})",
        member.user.username,
        member.nick.as_deref().unwrap_or("none")
    );

    if member.has_role("SOME_ROLE_ID") {
        println!("Member already has the target role");
    }
}
let api_member = guild.fetch_member(&rest, "USER_ID").await?;
let member = GuildMember::from_api(&api_member, &guild.id);

println!(
    "{} joined: {}",
    member.display_name(),
    member.joined_at.as_deref().unwrap_or("unknown")
);

ClientUser

The bot’s own account data. Available via client.user() after a successful login.

Fields

FieldTypeDescription
idSnowflakeBot account ID.
usernameStringBot username.
discriminatorStringDiscriminator.
global_nameOption<String>Display name.
avatarOption<String>Avatar hash.
botboolAlways true for a bot.
flagsOption<u32>Account flags.
verifiedOption<bool>Whether the account is verified.
emailOption<String>Email (only available via OAuth2).

Access

if let Some(me) = client.user() {
    println!("Bot: {} ({})", me.username, me.id);
}
client.user() returns None before login completes. Do not call it before the Ready event is received.

CdnOptions

Used in avatar_url, banner_url, icon_url, and similar methods.
FieldTypeDescription
sizeOption<u32>Image size in pixels. Must be a power of two (16–4096).
extensionOption<String>File format: "png", "webp", "jpg". Defaults to "png". For animated hashes (a_*) always uses "gif".
use fluxer_core::util::cdn::CdnOptions;

let opts = CdnOptions {
    size: Some(256),
    extension: Some("webp".to_string()),
};

if let Some(url) = user.avatar_url(&opts) {
    println!("Avatar: {url}");
} else {
    println!("Avatar: {}", user.display_avatar_url(&opts));
}