Struct serenity::model::guild::PartialGuild[][src]

#[non_exhaustive]
pub struct PartialGuild {
Show 37 fields pub application_id: Option<ApplicationId>, pub id: GuildId, pub afk_channel_id: Option<ChannelId>, pub afk_timeout: u64, pub default_message_notifications: DefaultMessageNotificationLevel, pub widget_enabled: Option<bool>, pub widget_channel_id: Option<ChannelId>, pub emojis: HashMap<EmojiId, Emoji>, pub features: Vec<String>, pub icon: Option<String>, pub mfa_level: MfaLevel, pub name: String, pub owner_id: UserId, pub owner: bool, pub region: String, pub roles: HashMap<RoleId, Role>, pub splash: Option<String>, pub discovery_splash: Option<String>, pub system_channel_id: Option<ChannelId>, pub system_channel_flags: SystemChannelFlags, pub rules_channel_id: Option<ChannelId>, pub public_updates_channel_id: Option<ChannelId>, pub verification_level: VerificationLevel, pub description: Option<String>, pub premium_tier: PremiumTier, pub premium_subscription_count: u64, pub banner: Option<String>, pub vanity_url_code: Option<String>, pub welcome_screen: Option<GuildWelcomeScreen>, pub approximate_member_count: Option<u64>, pub approximate_presence_count: Option<u64>, pub nsfw: bool, pub nsfw_level: NsfwLevel, pub max_video_channel_users: Option<u64>, pub max_presences: Option<u64>, pub max_members: Option<u64>, pub permissions: Option<String>,
}
Expand description

Partial information about a Guild. This does not include information like member data.

Fields (Non-exhaustive)

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
application_id: Option<ApplicationId>

Application ID of the guild creator if it is bot-created.

id: GuildId

The unique Id identifying the guild.

This is equivilant to the Id of the default role (@everyone) and also that of the default channel (typically #general).

afk_channel_id: Option<ChannelId>

Id of a voice channel that’s considered the AFK channel.

afk_timeout: u64

The amount of seconds a user can not show any activity in a voice channel before being moved to an AFK channel – if one exists.

default_message_notifications: DefaultMessageNotificationLevel

Indicator of whether notifications for all messages are enabled by default in the guild.

widget_enabled: Option<bool>

Whether or not the guild widget is enabled.

widget_channel_id: Option<ChannelId>

The channel id that the widget will generate an invite to, or null if set to no invite

emojis: HashMap<EmojiId, Emoji>

All of the guild’s custom emojis.

features: Vec<String>

Features enabled for the guild.

Refer to Guild::features for more information.

icon: Option<String>

The hash of the icon used by the guild.

In the client, this appears on the guild list on the left-hand side.

mfa_level: MfaLevel

Indicator of whether the guild requires multi-factor authentication for Roles or Users with moderation permissions.

name: String

The name of the guild.

owner_id: UserId

The Id of the User who owns the guild.

owner: bool

Whether or not the user is the owner of the guild.

region: String
👎 Deprecated:

Regions are now set per voice channel instead of globally.

The region that the voice servers that the guild uses are located in.

roles: HashMap<RoleId, Role>

A mapping of the guild’s roles.

splash: Option<String>

An identifying hash of the guild’s splash icon.

If the InviteSplash feature is enabled, this can be used to generate a URL to a splash image.

discovery_splash: Option<String>

An identifying hash of the guild discovery’s splash icon.

Note: Only present for guilds with the DISCOVERABLE feature.

system_channel_id: Option<ChannelId>

The ID of the channel to which system messages are sent.

system_channel_flags: SystemChannelFlags

System channel flags.

rules_channel_id: Option<ChannelId>

The id of the channel where rules and/or guidelines are displayed.

Note: Only available on COMMUNITY guild, see Self::features.

public_updates_channel_id: Option<ChannelId>

The id of the channel where admins and moderators of Community guilds receive notices from Discord.

Note: Only available on COMMUNITY guild, see Self::features.

verification_level: VerificationLevel

Indicator of the current verification level of the guild.

description: Option<String>

The guild’s description, if it has one.

premium_tier: PremiumTier

The server’s premium boosting level.

premium_subscription_count: u64

The total number of users currently boosting this server.

banner: Option<String>

The guild’s banner, if it has one.

vanity_url_code: Option<String>

The vanity url code for the guild, if it has one.

welcome_screen: Option<GuildWelcomeScreen>

The welcome screen of the guild.

Note: Only available on COMMUNITY guild, see Self::features.

approximate_member_count: Option<u64>

Approximate number of members in this guild.

approximate_presence_count: Option<u64>

Approximate number of non-offline members in this guild.

nsfw: bool
👎 Deprecated:

Removed in favor of Guild::nsfw_level.

Whether or not this guild is designated as NSFW. See discord support article.

nsfw_level: NsfwLevel

The guild NSFW state. See discord support article.

max_video_channel_users: Option<u64>

The maximum amount of users in a video channel.

max_presences: Option<u64>

The maximum number of presences for the guild. The default value is currently 25000.

Note: It is in effect when it is None.

max_members: Option<u64>

The maximum number of members for the guild.

permissions: Option<String>

The user permissions in the guild.

Implementations

Ban a User from the guild, deleting a number of days’ worth of messages (dmd) between the range 0 and 7.

Note: Requires the Ban Members permission.

Examples

Ban a member and remove all messages they’ve sent in the last 4 days:

// assumes a `user` and `guild` have already been bound
let _ = guild.ban(user, 4);
Errors

Returns a ModelError::DeleteMessageDaysAmount if the number of days’ worth of messages to delete is over the maximum.

Also may return Error::Http if the current user lacks permission.

Ban a User from the guild with a reason. Refer to Self::ban to further documentation.

Errors

In addition to the reasons Self::ban may return an error, can also return an error if the reason is too long.

Gets a list of the guild’s bans.

Requires the Ban Members permission.

Errors

Returns Error::Http if the current user lacks permission.

Gets a list of the guild’s audit log entries

Note: Requires the View Audit Log permission.

Errors

Returns Error::Http if the current user lacks permission, or if an invalid value is given.

Gets all of the guild’s channels over the REST API.

Errors

Returns Error::Http if the current user is not in the guild or if the guild is otherwise unavailable.

Creates a GuildChannel in the guild.

Refer to Http::create_channel for more information.

Requires the Manage Channels permission.

Examples

Create a voice channel in a guild with the name test:

use serenity::model::ChannelType;

guild.create_channel(|c| c.name("test").kind(ChannelType::Voice));
Errors

Returns Error::Http if the current user lacks permission, or if invalid data was given, such as the channel name being too long.

Creates an emoji in the guild with a name and base64-encoded image.

Refer to the documentation for Guild::create_emoji for more information.

Requires the Manage Emojis permission.

Examples

See the EditProfile::avatar example for an in-depth example as to how to read an image from the filesystem and encode it as base64. Most of the example can be applied similarly for this method.

Errors

Returns Error::Http if the current user lacks permission, if the emoji name is too long, or if the image is too large.

Creates an integration for the guild.

Requires the Manage Guild permission.

Errors

Returns Error::Http if the current user lacks permission.

Creates a guild specific ApplicationCommand

Note: Unlike global ApplicationCommands, guild commands will update instantly.

Errors

Returns the same possible errors as create_global_application_command.

Overrides all guild application commands.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Creates a guild specific ApplicationCommandPermission.

Note: It will update instantly.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Same as create_application_command_permission but allows to create more than one permission per call.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Get all guild application commands.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Get a specific guild application command by its Id.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Edit guild application command by its Id.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Delete guild application command by its Id.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Get all guild application commands permissions only.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Get permissions for specific guild application command by its Id.

Errors

If there is an error, it will be either Error::Http or Error::Json.

Creates a new role in the guild with the data set, if any.

See the documentation for Guild::create_role on how to use this.

Note: Requires the Manage Roles permission.

Errors

Returns Error::Http if the current user lacks permission, or if an invalid value was set.

Deletes the current guild if the current user is the owner of the guild.

Note: Requires the current user to be the owner of the guild.

Errors

Returns Error::Http if the current user is not the owner of the guild.

Deletes an Emoji from the guild.

Requires the Manage Emojis permission.

Errors

Returns Error::Http if the current user lacks permission, or if an emoji with that Id does not exist in the guild.

Deletes an integration by Id from the guild.

Requires the Manage Guild permission.

Errors

Returns Error::Http if the current user lacks permission, or if an integration with that Id does not exist in the guild.

Deletes a Role by Id from the guild.

Also see Role::delete if you have the cache and model features enabled.

Requires the Manage Roles permission.

Errors

Returns Error::Http if the current user lacks permission, or if a Role with that Id does not exist in the Guild.

Edits the current guild with new data where specified.

Note: Requires the current user to have the Manage Guild permission.

Errors

Returns Error::Http if an invalid value is set, or if the current user lacks permission to edit the guild.

Edits an Emoji’s name in the guild.

Also see Emoji::edit if you have the cache and methods features enabled.

Requires the Manage Emojis permission.

Errors

Returns Error::Http if the current user lacks permission, or if an emoji with that Id does not exist in the guild.

Edits the properties of member of the guild, such as muting or nicknaming them.

Refer to EditMember’s documentation for a full list of methods and permission restrictions.

Examples

Mute a member and set their roles to just one role with a predefined Id:

use serenity::model::GuildId;

GuildId(7).edit_member(user_id, |m| m.mute(true).roles(&vec![role_id])).await;
Errors

Returns Error::Http if the current user lacks the necessary permissions.

Edits the current user’s nickname for the guild.

Pass None to reset the nickname.

Note: Requires the Change Nickname permission.

Errors

Returns Error::Http if the current user lacks permission to change their nickname.

Edits a role, optionally setting its fields.

Requires the Manage Roles permission.

Examples

Make a role hoisted:

partial_guild.edit_role(&context, RoleId(7), |r| r.hoist(true));
Errors

Returns Error::Http if the current user lacks permission.

Edits the order of Roles Requires the Manage Roles permission.

Examples

Change the order of a role:

use serenity::model::id::RoleId;
partial_guild.edit_role_position(&context, RoleId(8), 2);
Errors

Returns Error::Http if the current user lacks permission.

Edits the GuildWelcomeScreen.

Errors

Returns an Error::Http if some mandatory fields are not provided.

Edits the GuildWidget.

Errors

Returns an Error::Http if the bot does not have the MANAGE_GUILD permission.

Gets a partial amount of guild data by its Id.

Errors

Returns Error::Http if the current user is not in the guild.

Returns which of two Users has a higher Member hierarchy.

Hierarchy is essentially who has the Role with the highest position.

Returns None if at least one of the given users’ member instances is not present. Returns None if the users have the same hierarchy, as neither are greater than the other.

If both user IDs are the same, None is returned. If one of the users is the guild owner, their ID is returned.

Calculate a Member’s permissions in the guild.

If member caching is enabled the cache will be checked first. If not found it will resort to an http request.

Cache is still required to look up roles.

Errors

See Guild::member.

Re-orders the channels of the guild.

Although not required, you should specify all channels’ positions, regardless of whether they were updated. Otherwise, positioning can sometimes get weird.

Note: Requires the Manage Channels permission.

Errors

Returns an Error::Http if the current user is lacking permission.

Returns a list of Members in a Guild whose username or nickname starts with a provided string.

Optionally pass in the limit to limit the number of results. Minimum value is 1, maximum and default value is 1000.

Note: Queries are case insensitive.

Errors

Returns an Error::Http if the API returns an error.

Starts a prune of Members.

See the documentation on GuildPrune for more information.

Note: Requires the Kick Members permission.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have permission to kick members.

Otherwise will return Error::Http if the current user does not have permission.

Can also return an Error::Json if there is an error deserializing the API response.

Kicks a Member from the guild.

Requires the Kick Members permission.

Errors

Returns Error::Http if the member cannot be kicked by the current user.

Errors

In addition to the reasons Self::kick may return an error, can also return an error if the reason is too long.

Returns a formatted URL of the guild’s icon, if the guild has an icon.

Returns a formatted URL of the guild’s banner, if the guild has a banner.

Gets all Emojis of this guild via HTTP.

Errors

Returns Error::Http if the guild is unavailable.

Gets an Emoji of this guild by its ID via HTTP.

Errors

Returns Error::Http if an Emoji with the given Id does not exist for the guild.

Gets all integration of the guild.

Requires the Manage Guild permission.

Errors

Returns Error::Http if the current user lacks permission.

Gets all of the guild’s invites.

Requires the Manage Guild permission.

Errors

Returns Error::Http if the current user lacks permission.

Leaves the guild.

Errors

Returns Error::Http if the current user is unable to leave the Guild, or currently is not in the guild.

Gets a user’s Member for the guild by Id.

Errors

Returns Error::Http if the member is not in the Guild, or if the Guild is otherwise unavailable.

Gets a list of the guild’s members.

Optionally pass in the limit to limit the number of results. Minimum value is 1, maximum and default value is 1000.

Optionally pass in after to offset the results by a User’s Id.

Errors

Returns an Error::Http if the API returns an error, may also return Error::NotInRange if the input is not within range.

Moves a member to a specific voice channel.

Requires the Move Members permission.

Errors

Returns an Error::Http if the current user lacks permission, or if the member is not currently in a voice channel for this Guild.

Calculate a Member’s permissions in a given channel in the guild.

Errors

Returns Error::Model if the Member has a non-existent Role for some reason.

Calculate a Role’s permissions in a given channel in the guild.

Errors

Returns Error::Model if the Role or Channel is not from this Guild.

Gets the number of Members that would be pruned with the given number of days.

Requires the Kick Members permission.

See Guild::prune_count.

Errors

Returns Error::Http if the current user lacks permission.

Returns the Id of the shard associated with the guild.

When the cache is enabled this will automatically retrieve the total number of shards.

Note: When the cache is enabled, this function unlocks the cache to retrieve the total number of shards in use. If you already have the total, consider using utils::shard_id.

Returns the formatted URL of the guild’s splash image, if one exists.

Starts an integration sync for the given integration Id.

Requires the Manage Guild permission.

Errors

See Guild::start_integration_sync.

Unbans a User from the guild.

Requires the Ban Members permission.

Errors

See Guild::unban.

Retrieve’s the guild’s vanity URL.

Note: Requires the Manage Guild permission.

Errors

See Guild::vanity_url.

Retrieves the guild’s webhooks.

Note: Requires the Manage Webhooks permission.

Errors

See Guild::webhooks.

Obtain a reference to a role by its name.

Note: If two or more roles have the same name, obtained reference will be one of them.

Examples

Obtain a reference to a Role by its name.

use serenity::model::prelude::*;
use serenity::prelude::*;

struct Handler;

#[serenity::async_trait]
impl EventHandler for Handler {
    async fn message(&self, context: Context, msg: Message) {
        if let Some(guild_id) = msg.guild_id {
            if let Some(guild) = guild_id.to_guild_cached(&context).await {
                if let Some(role) = guild.role_by_name("role_name") {
                    println!("Obtained role's reference: {:?}", role);
                }
            }
        }
    }
}

let mut client = Client::builder("token").event_handler(Handler).await?;

client.start().await?;

Gets the guild active threads.

Errors

Returns Error::Http if there is an error in the deserialization, or if the bot issuing the request is not in the guild.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Gets the Id of a partial guild.

Gets the Id of a partial guild.

Performs the conversion.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more