#[non_exhaustive]
pub struct Guild {
Show 45 fields pub afk_channel_id: Option<ChannelId>, pub afk_timeout: u64, pub application_id: Option<ApplicationId>, pub channels: HashMap<ChannelId, Channel>, pub default_message_notifications: DefaultMessageNotificationLevel, pub emojis: HashMap<EmojiId, Emoji>, pub explicit_content_filter: ExplicitContentFilter, pub features: Vec<String>, pub icon: Option<String>, pub id: GuildId, pub joined_at: Timestamp, pub large: bool, pub member_count: u64, pub members: HashMap<UserId, Member>, pub mfa_level: MfaLevel, pub name: String, pub owner_id: UserId, pub presences: HashMap<UserId, Presence>, 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 voice_states: HashMap<UserId, VoiceState>, pub description: Option<String>, pub premium_tier: PremiumTier, pub premium_subscription_count: u64, pub banner: Option<String>, pub vanity_url_code: Option<String>, pub preferred_locale: String, pub welcome_screen: Option<GuildWelcomeScreen>, pub approximate_member_count: Option<u64>, pub approximate_presence_count: Option<u64>, pub nsfw_level: NsfwLevel, pub max_video_channel_users: Option<u64>, pub max_presences: Option<u64>, pub max_members: Option<u64>, pub widget_enabled: Option<bool>, pub widget_channel_id: Option<ChannelId>, pub stage_instances: Vec<StageInstance>, pub threads: Vec<GuildChannel>, pub stickers: HashMap<StickerId, Sticker>,
}
Expand description

Information about a Discord guild, such as channels, emojis, etc.

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.
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.

application_id: Option<ApplicationId>

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

channels: HashMap<ChannelId, Channel>

All voice and text channels contained within a guild.

This contains all channels regardless of permissions (i.e. the ability of the bot to read from or connect to them).

default_message_notifications: DefaultMessageNotificationLevel

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

emojis: HashMap<EmojiId, Emoji>

All of the guild’s custom emojis.

explicit_content_filter: ExplicitContentFilter

Default explicit content filter level.

features: Vec<String>

The guild features. More information available at discord documentation.

The following is a list of known features:

  • ANIMATED_ICON
  • BANNER
  • COMMERCE
  • COMMUNITY
  • DISCOVERABLE
  • FEATURABLE
  • INVITE_SPLASH
  • MEMBER_VERIFICATION_GATE_ENABLED
  • MONETIZATION_ENABLED
  • MORE_STICKERS
  • NEWS
  • PARTNERED
  • PREVIEW_ENABLED
  • PRIVATE_THREADS
  • ROLE_ICONS
  • SEVEN_DAY_THREAD_ARCHIVE
  • THREE_DAY_THREAD_ARCHIVE
  • TICKETED_EVENTS_ENABLED
  • VANITY_URL
  • VERIFIED
  • VIP_REGIONS
  • WELCOME_SCREEN_ENABLED
  • THREE_DAY_THREAD_ARCHIVE
  • SEVEN_DAY_THREAD_ARCHIVE
  • PRIVATE_THREADS
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.

id: GuildId

The unique Id identifying the guild.

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

joined_at: Timestamp

The date that the current user joined the guild.

large: bool

Indicator of whether the guild is considered “large” by Discord.

member_count: u64

The number of members in the guild.

members: HashMap<UserId, Member>

Users who are members of the guild.

Members might not all be available when the ReadyEvent is received if the Self::member_count is greater than the LARGE_THRESHOLD set by the library.

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.

presences: HashMap<UserId, Presence>

A mapping of Users’ Ids to their current presences.

Note: This will be empty unless the “guild presences” privileged intent is enabled.

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.

voice_states: HashMap<UserId, VoiceState>

A mapping of Users to their current voice state.

description: Option<String>

The server’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.

preferred_locale: String

The preferred locale of this guild only set if guild has the “DISCOVERABLE” feature, defaults to en-US.

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_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.

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

stage_instances: Vec<StageInstance>

The stage instances in this guild.

threads: Vec<GuildChannel>

All active threads in this guild that current user has permission to view.

stickers: HashMap<StickerId, Sticker>

All of the guild’s custom stickers.

Implementations

Available on crate feature model only.

Returns the “default” channel of the guild for the passed user id. (This returns the first channel that can be read by the user, if there isn’t one, returns None)

Available on crate feature model only.

Returns the guaranteed “default” channel of the guild. (This returns the first channel that can be read by everyone, if there isn’t one, returns None)

Note: This is very costly if used in a server with lots of channels, members, or both.

Available on crate features model and cache only.
Available on crate feature model only.

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

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

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.

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have permission to perform bans, or may return a ModelError::Hierarchy if the member to be banned has a higher role than the current user.

Otherwise returns Error::Http if the member cannot be banned.

Available on crate feature model only.

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

Errors

In addition to the possible reasons Self::ban may return an error, an Error::ExceededLimit may also be returned if the reason is too long.

Available on crate feature model only.

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

Available on crate feature model only.

Retrieves a list of Bans for the guild.

Note: Requires the Ban Members permission.

Errors

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

Available on crate feature model only.

Adds a User to this guild with a valid OAuth2 access token.

Returns the created Member object, or nothing if the user is already a member of the guild.

Errors

Returns Error::Http if the current user lacks permission, or if invalid values are set.

Available on crate feature model only.

Retrieves a list of AuditLogs for the guild.

Note: Requires the View Audit Log permission.

Errors

Returns Error::Http if the current user does not have permission to view the audit log, or if an invalid value is given.

Available on crate feature model only.

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

Errors

Returns Error::Http if the guild is currently unavailable.

Available on crate feature model only.

Creates a guild with the data provided.

Only a PartialGuild will be immediately returned, and a full Guild will be received over a Shard.

Note: This endpoint is usually only available for user accounts. Refer to Discord’s information for the endpoint here for more information. If you require this as a bot, re-think what you are doing and if it really needs to be doing this.

Examples

Create a guild called "test" in the [US West region] with no icon:

use serenity::model::Guild;

let _guild = Guild::create_guild(&http, "test", None).await;
Errors

Returns Error::Http if the current user cannot create a Guild.

Available on crate feature model only.

Creates a new Channel in the guild.

Note: Requires the Manage Channels permission.

Examples
use serenity::model::ChannelType;

// assuming a `guild` has already been bound

let _ = guild
    .create_channel(&http, |c| c.name("my-test-channel").kind(ChannelType::Text))
    .await;
Errors

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

Otherwise will return Error::Http if the current user lacks permission.

Available on crate feature model only.

Creates an emoji in the guild with a name and base64-encoded image. The utils::read_image function is provided for you as a simple method to read an image and encode it into base64, if you are reading from the filesystem.

The name of the emoji must be at least 2 characters long and can only contain alphanumeric characters and underscores.

Requires the Manage Emojis and Stickers 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.

Available on crate feature model only.

Creates an integration for the guild.

Requires the Manage Guild permission.

Errors

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

Available on crate feature model only.

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.

Available on crate feature model only.

Overrides all guild application commands.

Errors

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

Available on crate feature model only.

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.

Available on crate feature model only.

Overrides all application commands permissions.

Errors

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

Available on crate feature model only.

Get all guild application commands.

Errors

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

Available on crate feature model only.

Get a specific guild application command by its Id.

Errors

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

Available on crate feature model only.

Edit guild application command by its Id.

Errors

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

Available on crate feature model only.

Delete guild application command by its Id.

Errors

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

Available on crate feature model only.

Get all guild application commands permissions only.

Errors

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

Available on crate feature model only.

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.

Available on crate feature model only.

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

Note: Requires the Manage Roles permission.

Examples

Create a role which can be mentioned, with the name ‘test’:

// assuming a `guild` has been bound

let role = guild.create_role(&http, |r| r.hoist(true).name("role")).await;
Errors

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

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

Available on crate feature model only.

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

Note: Requres the Manage Events permission.

Errors

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

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

Available on crate feature model only.

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

Note: Requires the Manage Emojis and Stickers permission.

Errors

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

Available on crate feature model only.

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

If the cache is enabled, then returns a ModelError::InvalidUser if the current user is not the guild owner.

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

Available on crate feature model only.

Deletes an Emoji from the guild.

Requires the Manage Emojis and Stickers permission.

Errors

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

Available on crate feature model only.

Deletes an integration by Id from the guild.

Requires the Manage Guild permission.

Errors

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

Available on crate feature model only.

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 to delete the role.

Available on crate feature model only.

Deletes a Scheduled Event by Id from the guild.

Requires the Manage Events permission.

Errors

Returns Error::Http if the current user lacks permission to delete the scheduled event.

Available on crate feature model only.

Deletes a Sticker by Id from the guild.

Requires the Manage Emojis and Stickers permission.

Errors

Returns Error::Http if the current user lacks permission to delete the sticker.

Available on crate feature model only.

Edits the current guild with new data where specified.

Refer to EditGuild’s documentation for a full list of methods.

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

Examples

Change a guild’s icon using a file name “icon.png”:

use serenity::utils;

// We are using read_image helper function from utils.
let base64_icon = utils::read_image("./icon.png")
    .expect("Failed to read image");

guild.edit(|g| g.icon(base64_icon));
Errors

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

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

Available on crate feature model only.

Edits an Emoji’s name in the guild.

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

Requires the Manage Emojis and Stickers permission.

Errors

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

Available on crate feature model only.

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

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:

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

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

Available on crate feature model only.

Edits the current user’s nickname for the guild.

Pass None to reset the nickname.

Note: Requires the Change Nickname permission.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have permission to change their own nickname.

Otherwise will return Error::Http if the current user lacks permission.

Available on crate feature model only.

Edits a role, optionally setting its fields.

Requires the Manage Roles permission.

Examples

Make a role hoisted:

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

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

Available on crate feature model only.

Edits the order of Roles Requires the Manage Roles permission.

Examples

Change the order of a role:

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

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

Available on crate feature model only.

Modifies a scheduled event in the guild with the data set, if any.

Note: Requres the Manage Events permission.

Errors

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

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

Available on crate feature model only.

Edits a sticker, optionally setting its fields.

Requires the Manage Emojis and Stickers permission.

Examples

Rename a sticker:

guild.edit_sticker(&context, StickerId(7), |r| r.name("Bun bun meow"));
Errors

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

Available on crate feature model only.

Edits the GuildWelcomeScreen.

Errors

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

Available on crate feature model only.

Edits the GuildWidget.

Errors

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

Available on crate feature model only.

Gets a partial amount of guild data by its Id.

Note: This will not be a Guild, as the REST API does not send all data with a guild retrieval.

Errors

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

Available on crate features model and cache only.

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.

Available on crate feature model only.

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

This will produce a WEBP image URL, or GIF if the guild has a GIF icon.

Available on crate feature model only.

Gets all Emojis of this guild via HTTP.

Errors

Returns Error::Http if the guild is unavailable

Available on crate feature model only.

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

Errors

Returns an Error::Http if an emoji with that Id does not exist in the guild, or if the guild is unavailable.

May also return Error::Json if there is an error in deserialzing the API response.

Available on crate feature model only.

Gets all integration of the guild.

Note: Requires the Manage Guild permission.

Errors

Returns Error::Http if the current user does not have permission to see integrations.

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

Available on crate feature model only.

Retrieves the active invites for the guild.

Note: Requires the Manage Guild permission.

Errors

If the cache is enabled, returns ModelError::InvalidPermissions if the current user does not have permission to see invites.

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

Available on crate feature model only.

Checks if the guild is ‘large’. A guild is considered large if it has more than 250 members.

Available on crate feature model only.

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.

Available on crate feature model only.
Errors

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

Available on crate feature model only.

Leaves the guild.

Errors

May return an Error::Http if the current user cannot leave the guild, or currently is not in the guild.

Available on crate feature model only.

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

Errors

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

Available on crate feature model only.

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.

Available on crate feature model only.

Gets a list of all the members (satisfying the status provided to the function) in this guild.

Available on crate feature model only.

Retrieves the first Member found that matches the name - with an optional discriminator - provided.

Searching with a discriminator given is the most precise form of lookup, as no two people can share the same username and discriminator.

If a member can not be found by username or username#discriminator, then a search will be done for the nickname. When searching by nickname, the hash (#) and everything after it is included in the search.

The following are valid types of searches:

  • username: “zey”
  • username and discriminator: “zey#5479”

Note: This will only search members that are cached. If you want to search all members in the guild via the Http API, use Self::search_members.

Available on crate feature model only.

Retrieves all Member that start with a given String.

sorted decides whether the best early match of the prefix should be the criteria to sort the result. For the prefix “zey” and the unsorted result:

  • “zeya”, “zeyaa”, “zeyla”, “zeyzey”, “zeyzeyzey” It would be sorted:
  • “zeya”, “zeyaa”, “zeyla”, “zeyzey”, “zeyzeyzey”

Locking: First collects a Member’s User-name by read-locking all inner Users, and then sorts. This ensures that no name is being changed after being sorted in the originally correct position. However, since the read-locks are dropped after borrowing the name, the names might have been changed by the user, the sorted list cannot account for this.

Note: This will only search members that are cached. If you want to search all members in the guild via the Http API, use Self::search_members.

Available on crate feature model only.

Retrieves all Member containing a given String as either username or nick, with a priority on username.

If the substring is “yla”, following results are possible:

  • “zeyla”, “meiyla”, “yladenisyla” If ‘case_sensitive’ is false, the following are not found:
  • “zeYLa”, “meiyLa”, “LYAdenislyA”

sorted decides whether the best early match of the search-term should be the criteria to sort the result. It will look at the account name first, if that does not fit the search-criteria substring, the display-name will be considered. For the substring “zey” and the unsorted result:

  • “azey”, “zey”, “zeyla”, “zeylaa”, “zeyzeyzey” It would be sorted:
  • “zey”, “azey”, “zeyla”, “zeylaa”, “zeyzeyzey”

Note: Due to two fields of a Member being candidates for the searched field, setting sorted to true will result in an overhead, as both fields have to be considered again for sorting.

Locking: First collects a Member’s User-name by read-locking all inner Users, and then sorts. This ensures that no name is being changed after being sorted in the originally correct position. However, since the read-locks are dropped after borrowing the name, the names might have been changed by the user, the sorted list cannot account for this.

Note: This will only search members that are cached. If you want to search all members in the guild via the Http API, use Self::search_members.

Available on crate feature model only.

Retrieves a tuple of Members containing a given String in their username as the first field and the name used for sorting as the second field.

If the substring is “yla”, following results are possible:

  • “zeyla”, “meiyla”, “yladenisyla” If ‘case_sensitive’ is false, the following are not found:
  • “zeYLa”, “meiyLa”, “LYAdenislyA”

sort decides whether the best early match of the search-term should be the criteria to sort the result. For the substring “zey” and the unsorted result:

  • “azey”, “zey”, “zeyla”, “zeylaa”, “zeyzeyzey” It would be sorted:
  • “zey”, “azey”, “zeyla”, “zeylaa”, “zeyzeyzey”

Locking: First collects a Member’s User-name by read-locking all inner Users, and then sorts. This ensures that no name is being changed after being sorted in the originally correct position. However, since the read-locks are dropped after borrowing the name, the names might have been changed by the user, the sorted list cannot account for this.

Note: This will only search members that are cached. If you want to search all members in the guild via the Http API, use Self::search_members.

Available on crate feature model only.

Retrieves all Member containing a given String in their nick.

If the substring is “yla”, following results are possible:

  • “zeyla”, “meiyla”, “yladenisyla” If ‘case_sensitive’ is false, the following are not found:
  • “zeYLa”, “meiyLa”, “LYAdenislyA”

sort decides whether the best early match of the search-term should be the criteria to sort the result. For the substring “zey” and the unsorted result:

  • “azey”, “zey”, “zeyla”, “zeylaa”, “zeyzeyzey” It would be sorted:
  • “zey”, “azey”, “zeyla”, “zeylaa”, “zeyzeyzey”

Note: Instead of panicking, when sorting does not find a nick, the username will be used (this should never happen).

Locking: First collects a Member’s nick directly or by read-locking all inner Users (in case of no nick, see note above), and then sorts. This ensures that no name is being changed after being sorted in the originally correct position. However, since the read-locks are dropped after borrowing the name, the names might have been changed by the user, the sorted list cannot account for this.

Note: This will only search members that are cached. If you want to search all members in the guild via the Http API, use Self::search_members.

Available on crate features model and cache only.

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.

Available on crate feature model only.

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.

Available on crate feature model only.

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.

Available on crate feature model only.

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

Errors

Will return an Error::Model if the Role or Channel is not from this Guild.

Available on crate feature model only.

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

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 may return Error::Http if the current user does not have permission. Can also return Error::Json if there is an error in deserializing the API response.

Available on crate feature model only.

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.

Available on crate feature model only.

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.

Available on crate feature model only.

Fetches a specifified scheduled event in the guild, by Id. If with_user_count is set to true, then the user_count field will be populated, indicating the number of users interested in the event.

Note: Requres the Manage Events permission.

Errors

Returns Error::Http if the current user lacks permission, or if the provided Id is invalid.

Available on crate feature model only.

Fetches a list of all scheduled events in the guild. If with_user_count is set to true, then each event returned will have its user_count field populated.

Note: Requres the Manage Events permission.

Errors

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

Available on crate feature model only.

Fetches a list of interested users for the specified event.

If limit is left unset, by default at most 100 users are returned.

Note: Requires the Manage Events permission.

Errors

Returns Error::Http if the current user lacks permission, or if the provided Id is invalid.

Available on crate feature model only.

Fetches a list of interested users for the specified event, with additional options and filtering. See Http::get_scheduled_event_users for details.

Note: Requires the Manage Events permission.

Errors

Returns Error::Http if the current user lacks permission, or if the provided Id is invalid.

Available on crate features cache and utils and model only.

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.

Available on crate feature model only.

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

Available on crate feature model only.

Starts an integration sync for the given integration Id.

Requires the Manage Guild permission.

Errors

Returns an Error::Http if the current user does not have permission, or if an Integration with that Id does not exist.

Available on crate feature model only.

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.

Available on crate feature model only.

Unbans the given User from the guild.

Note: Requires the Ban Members permission.

Errors

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

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

Available on crate feature model only.

Retrieve’s the guild’s vanity URL.

Note: Requires the Manage Guild permission.

Errors

Will return Error::Http if the current user is lacking permissions. Can also return an Error::Json if there is an error deserializing the API response.

Available on crate feature model only.

Retrieves the guild’s webhooks.

Note: Requires the Manage Webhooks permission.

Errors

Will return an Error::Http if the current user is lacking permissions. Can also return an Error::Json if there is an error deserializing the API response.

Available on crate feature model only.

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, ctx: Context, msg: Message) {
        if let Some(guild_id) = msg.guild_id {
            if let Some(guild) = guild_id.to_guild_cached(&ctx) {
                if let Some(role) = guild.role_by_name("role_name") {
                    println!("{:?}", role);
                }
            }
        }
    }
}

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

client.start().await?;
Available on crate features model and collector only.

Returns a future that will await one message sent in this guild.

Available on crate features model and collector only.

Returns a stream builder which can be awaited to obtain a stream of messages in this guild.

Available on crate features model and collector only.

Await a single reaction in this guild.

Available on crate features model and collector only.

Returns a stream builder which can be awaited to obtain a stream of reactions sent in this guild.

Available on crate feature model only.

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

Look up a Guild, either by ID or by a string case-insensitively.

Requires the cache feature to be enabled.

Available on crate features utils and client only.

The associated error which can be returned from parsing.

Available on crate features utils and client only.

Parses a string s as a command parameter of this type.

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 Guild.

Gets the Id of Guild.

Converts this Guild instance into a PartialGuild

PartialGuild is not a strict subset and contains some data specific to the current user that Guild does not contain. Therefore, this method needs access to cache and HTTP to generate the missing data

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

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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