Struct serenity::model::Guild [] [src]

pub struct Guild {
    pub afk_channel_id: Option<ChannelId>,
    pub afk_timeout: u64,
    pub channels: HashMap<ChannelId, Arc<RwLock<GuildChannel>>>,
    pub default_message_notifications: u64,
    pub emojis: HashMap<EmojiId, Emoji>,
    pub features: Vec<Feature>,
    pub icon: Option<String>,
    pub id: GuildId,
    pub joined_at: DateTime<FixedOffset>,
    pub large: bool,
    pub member_count: u64,
    pub members: HashMap<UserId, Member>,
    pub mfa_level: u64,
    pub name: String,
    pub owner_id: UserId,
    pub presences: HashMap<UserId, Presence>,
    pub region: String,
    pub roles: HashMap<RoleId, Role>,
    pub splash: Option<String>,
    pub verification_level: VerificationLevel,
    pub voice_states: HashMap<UserId, VoiceState>,
}

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

Fields

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

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.

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

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

All of the guild's custom emojis.

VIP features enabled for the guild. Can be obtained through the Discord Partnership website.

The hash of the icon used by the guild.

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

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

The date that the current user joined the guild.

Indicator of whether the guild is considered "large" by Discord.

The number of members in the guild.

Users who are members of the guild.

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

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

The name of the guild.

The Id of the User who owns the guild.

A mapping of Users' Ids to their current presences.

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

A mapping of the guild's roles.

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.

Indicator of the current verification level of the guild.

A mapping of of Users to their current voice state.

Methods

impl Guild
[src]

Ban a User from the guild. All messages by the user within the last given number of days given will be deleted.

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::InvalidPermissions if the current user does not have permission to perform bans.

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

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.

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

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, Region};

let _guild = Guild::create_guild("test", Region::UsWest, None);

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("my-test-channel", ChannelType::Text);

Errors

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

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

Creates an integration for the guild.

Requires the Manage Guild permission.

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(|r| r.hoist(true).name("role"));

Errors

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

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.

Deletes an Emoji from the guild.

Requires the Manage Emojis permission.

Deletes an integration by Id from the guild.

Requires the Manage Guild permission.

Deletes a Role by Id from the guild.

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

Requires the Manage Roles permission.

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

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.

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:

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

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.

Edits a role, optionally setting its fields.

Requires the Manage Roles permission.

Examples

Make a role hoisted:

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

Gets an emoji in the guild by Id.

Requires the Manage Emojis permission.

Gets a list of all of the guild's emojis.

Requires the Manage Emojis permission.

Gets a partial amount of guild data by its Id.

Requires that the current user be in the guild.

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

Gets all integration of the guild.

This performs a request over the REST API.

Retrieves the active invites for the guild.

Note: Requires the Manage Guild permission.

Errors

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

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

Kicks a Member from the guild.

Requires the Kick Members permission.

Leaves the guild.

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

Gets a list of the guild's members.

Optionally pass in the limit to limit the number of results. Maximum value is 1000. Optionally pass in after to offset the results by a User's Id.

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"
  • nickname: "zeyla" or "zeylas#nick"

Moves a member to a specific voice channel.

Requires the Move Members permission.

Calculate a User's permissions in a given channel in the guild.

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

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.

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

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.

Retrieves the guild's webhooks.

Note: Requires the Manage Webhooks permission.

Deprecated since 0.1.5

: Use bans instead.

Alias of bans.

Deprecated since 0.1.5

: Use channels instead.

Alias of channels.

Deprecated since 0.1.5

: Use emoji instead.

Alias of emoji.

Deprecated since 0.1.5

: Use emojis instead.

Alias of emojis.

Deprecated since 0.1.5

: Use integrations instead.

Alias of integrations.

Deprecated since 0.1.5

: Use invites instead.

Alias of invites.

Deprecated since 0.1.5

: Use member instead.

Alias of member.

Deprecated since 0.1.5

: Use members instead.

Alias of members.

Deprecated since 0.1.5

: Use member_named instead.

Alias of member_named.

Deprecated since 0.1.5

: Use prune_count instead.

Alias of prune_count.

Deprecated since 0.1.5

: Use webhooks instead.

Alias of webhooks.

Trait Implementations

impl Clone for Guild
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Guild
[src]

Formats the value using the given formatter.

impl<'de> Deserialize<'de> for Guild
[src]

Deserialize this value from the given Serde deserializer. Read more