Struct serenity::model::Guild
[−]
[src]
pub struct Guild { pub afk_channel_id: Option<ChannelId>, pub afk_timeout: u64, pub channels: HashMap<ChannelId, 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: String, 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
afk_channel_id: Option<ChannelId>
Id of a voice channel that's considered AFK.
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.
channels: HashMap<ChannelId, GuildChannel>
All voice and text channels a guild has. This gives all of them regardless of permissions.
default_message_notifications: u64
Lets you know if notifications for all messages are enabled by default in the guild.
emojis: HashMap<EmojiId, Emoji>
All custom emojis of a guild. Such are made using the API or Twitch integrations.
features: Vec<Feature>
VIP guild features a guild has. Can be obtained through Discord Partnership website.
icon: Option<String>
Optional guild icon that appears in sidebar.
id: GuildId
Guild's Id which is also the Id of the default role and channel.
joined_at: String
large: bool
Set to true if guild has a lot of users.
True indicates that offline guild members aren't initially sent.
member_count: u64
The amount of members in guild.
members: HashMap<UserId, Member>
Members of the guild. Members might not all be available on start-up if the large
field is true
.
mfa_level: u64
Indicator if guild requires 2-factor authentication for roles with certain permissions.
name: String
The guild's name.
owner_id: UserId
Id of the guild's owner.
presences: HashMap<UserId, Presence>
Presence statuses of members.
region: String
The region that the guild's voice servers are located in.
roles: HashMap<RoleId, Role>
All roles a guild has.
splash: Option<String>
If InviteSplash feature is enabled, this can point to splash image URL displayed when someone opens invite URL.
verification_level: VerificationLevel
Determines the verification level.
voice_states: HashMap<UserId, VoiceState>
Lets you know what voice channels user have joined.
Methods
impl Guild
[src]
fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8) -> Result<()>
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 ClientError::InvalidPermissions
if the current user does
not have permission to perform bans.
Returns a ClientError::DeleteMessageDaysAmount
if the number of
days' worth of messages to delete is over the maximum.
fn bans(&self) -> Result<Vec<Ban>>
Retrieves a list of Ban
s for the guild.
Note: Requires the Ban Members permission.
Errors
If the cache
is enabled, returns a ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn create(name: &str,
region: Region,
icon: Option<&str>)
-> Result<PartialGuild>
region: Region,
icon: Option<&str>)
-> Result<PartialGuild>
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);
fn create_channel(&mut self,
name: &str,
kind: ChannelType)
-> Result<GuildChannel>
name: &str,
kind: ChannelType)
-> Result<GuildChannel>
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 ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn create_emoji(&self, name: &str, image: &str) -> Result<Emoji>
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.
fn create_integration<I>(&self, integration_id: I, kind: &str) -> Result<()> where I: Into<IntegrationId>
Creates an integration for the guild.
Requires the Manage Guild permission.
fn create_role<F>(&self, f: F) -> Result<Role> where F: FnOnce(EditRole) -> EditRole
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':
let role = context.create_role(guild_id, |r| r .hoist(true) .name("role"));
Errors
If the cache
is enabled, returns a ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn delete(&self) -> Result<PartialGuild>
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 ClientError::InvalidUser
if the current user is not the guild owner.
fn delete_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<()>
Deletes an Emoji
from the guild.
Requires the Manage Emojis permission.
fn delete_integration<I: Into<IntegrationId>>(&self,
integration_id: I)
-> Result<()>
integration_id: I)
-> Result<()>
Deletes an integration by Id from the guild.
Requires the Manage Guild permission.
fn delete_role<R: Into<RoleId>>(&self, role_id: R) -> Result<()>
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.
fn edit<F>(&mut self, f: F) -> Result<()> where F: FnOnce(EditGuild) -> EditGuild
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 ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn edit_emoji<E: Into<EmojiId>>(&self, emoji_id: E, name: &str) -> Result<Emoji>
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.
fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()> where F: FnOnce(EditMember) -> EditMember, U: Into<UserId>
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]));
fn edit_nickname(&self, new_nickname: Option<&str>) -> Result<()>
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 ClientError::InvalidPermissions
if the current user does not have permission to change their own
nickname.
fn edit_role<F, R>(&self, role_id: R, f: F) -> Result<Role> where F: FnOnce(EditRole) -> EditRole, R: Into<RoleId>
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));
fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild>
Gets a partial amount of guild data by its Id.
Requires that the current user be in the guild.
fn get_bans(&self) -> Result<Vec<Ban>>
Gets a list of the guild's bans.
Requires the [Ban Members] permission.
fn get_channels(&self) -> Result<HashMap<ChannelId, GuildChannel>>
Gets all of the guild's channels over the REST API.
fn get_emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji>
Gets an emoji in the guild by Id.
Requires the Manage Emojis permission.
fn get_emojis(&self) -> Result<Vec<Emoji>>
Gets a list of all of the guild's emojis.
Requires the Manage Emojis permission.
fn get_integrations(&self) -> Result<Vec<Integration>>
Gets all integration of the guild.
This performs a request over the REST API.
fn get_invites(&self) -> Result<Vec<RichInvite>>
Retrieves the active invites for the guild.
Note: Requires the Manage Guild permission.
Errors
If the cache
is enabled, returns a ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn get_member<U: Into<UserId>>(&self, user_id: U) -> Result<Member>
Gets a user's Member
for the guild by Id.
fn get_members<U>(&self,
limit: Option<u64>,
after: Option<U>)
-> Result<Vec<Member>> where U: Into<UserId>
limit: Option<u64>,
after: Option<U>)
-> Result<Vec<Member>> where U: Into<UserId>
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.
fn get_member_named(&self, name: &str) -> Option<&Member>
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"
fn get_prune_count(&self, days: u16) -> Result<GuildPrune>
Retrieves the count of the number of Member
s 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 ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn get_webhooks(&self) -> Result<Vec<Webhook>>
Retrieves the guild's webhooks.
Note: Requires the Manage Webhooks permission.
fn icon_url(&self) -> Option<String>
Returns the formatted URL of the guild's icon, if one exists.
fn is_large(&self) -> bool
Checks if the guild is 'large'. A guild is considered large if it has more than 250 members.
fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()>
Kicks a Member
from the guild.
Requires the Kick Members permission.
fn leave(&self) -> Result<PartialGuild>
Leaves the guild.
fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()> where C: Into<ChannelId>, U: Into<UserId>
Moves a member to a specific voice channel.
Requires the Move Members permission.
fn permissions_for<C, U>(&self, channel_id: C, user_id: U) -> Permissions where C: Into<ChannelId>, U: Into<UserId>
Calculate a User
's permissions in a given channel in the guild.
fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult>
Performs a search request to the API for the guild's Message
s.
This will search all of the guild's Channel
s at once, that you have
the Read Message History permission to. Use search_channels
to
specify a list of channels to search, where all other
channels will be excluded.
Refer to the documentation for the Search
builder for examples and
more information.
Note: Bot users can not search.
Errors
If the cache
is enabled, returns a
ClientError::InvalidOperationAsBot
if the current user is a bot.
fn search_channels<F>(&self,
channel_ids: &[ChannelId],
f: F)
-> Result<SearchResult> where F: FnOnce(Search) -> Search
channel_ids: &[ChannelId],
f: F)
-> Result<SearchResult> where F: FnOnce(Search) -> Search
Performs a search request to the API for the guild's Message
s in
given channels.
This will search all of the messages in the guild's provided
Channel
s by Id that you have the Read Message History permission
to. Use search
to search all of a guild's channels
at once.
Refer to the documentation for the Search
builder for examples and
more information.
Note: Bot users can not search.
Errors
If the cache
is enabled, returns a
ClientError::InvalidOperationAsBot
if the current user is a bot.
fn splash_url(&self) -> Option<String>
Returns the formatted URL of the guild's splash image, if one exists.
fn start_integration_sync<I: Into<IntegrationId>>(&self,
integration_id: I)
-> Result<()>
integration_id: I)
-> Result<()>
Starts an integration sync for the given integration Id.
Requires the Manage Guild permission.
fn start_prune(&self, days: u16) -> Result<GuildPrune>
Starts a prune of Member
s.
See the documentation on GuildPrune
for more information.
Note: Requires the Kick Members permission.
Errors
If the cache
is enabled, returns a ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()>
Unbans the given User
from the guild.
Note: Requires the Ban Members permission.
Errors
If the cache
is enabled, returns a ClientError::InvalidPermissions
if the current user does not have permission to perform bans.
Trait Implementations
impl Clone for Guild
[src]
fn clone(&self) -> Guild
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more