#[non_exhaustive]pub struct Guild {Show 51 fields
pub id: GuildId,
pub name: String,
pub icon: Option<ImageHash>,
pub icon_hash: Option<ImageHash>,
pub splash: Option<ImageHash>,
pub discovery_splash: Option<ImageHash>,
pub owner_id: UserId,
pub afk_metadata: Option<AfkMetadata>,
pub widget_enabled: Option<bool>,
pub widget_channel_id: Option<ChannelId>,
pub verification_level: VerificationLevel,
pub default_message_notifications: DefaultMessageNotificationLevel,
pub explicit_content_filter: ExplicitContentFilter,
pub roles: HashMap<RoleId, Role>,
pub emojis: HashMap<EmojiId, Emoji>,
pub features: Vec<String>,
pub mfa_level: MfaLevel,
pub application_id: Option<ApplicationId>,
pub system_channel_id: Option<ChannelId>,
pub system_channel_flags: SystemChannelFlags,
pub rules_channel_id: Option<ChannelId>,
pub max_presences: Option<u64>,
pub max_members: Option<u64>,
pub vanity_url_code: Option<String>,
pub description: Option<String>,
pub banner: Option<String>,
pub premium_tier: PremiumTier,
pub premium_subscription_count: Option<u64>,
pub preferred_locale: String,
pub public_updates_channel_id: Option<ChannelId>,
pub max_video_channel_users: Option<u64>,
pub max_stage_video_channel_users: Option<u64>,
pub approximate_member_count: Option<u64>,
pub approximate_presence_count: Option<u64>,
pub welcome_screen: Option<GuildWelcomeScreen>,
pub nsfw_level: NsfwLevel,
pub stickers: HashMap<StickerId, Sticker>,
pub premium_progress_bar_enabled: bool,
pub joined_at: Timestamp,
pub large: bool,
pub unavailable: bool,
pub member_count: u64,
pub voice_states: HashMap<UserId, VoiceState>,
pub members: HashMap<UserId, Member>,
pub channels: HashMap<ChannelId, GuildChannel>,
pub threads: Vec<GuildChannel>,
pub presences: HashMap<UserId, Presence>,
pub stage_instances: Vec<StageInstance>,
pub scheduled_events: Vec<ScheduledEvent>,
pub safety_alerts_channel_id: Option<ChannelId>,
pub incidents_data: Option<IncidentsData>,
}Expand description
Information about a Discord guild, such as channels, emojis, etc.
Discord docs plus extension.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: GuildIdThe unique Id identifying the guild.
This is equivalent to the Id of the default role (@everyone).
name: StringThe name of the guild.
icon: Option<ImageHash>The hash of the icon used by the guild.
In the client, this appears on the guild list on the left-hand side.
icon_hash: Option<ImageHash>Icon hash, returned when in the template object
splash: Option<ImageHash>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<ImageHash>An identifying hash of the guild discovery’s splash icon.
Note: Only present for guilds with the DISCOVERABLE feature.
owner_id: UserIdThe Id of the User who owns the guild.
afk_metadata: Option<AfkMetadata>Information about the voice afk channel.
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
verification_level: VerificationLevelIndicator of the current verification level of the guild.
default_message_notifications: DefaultMessageNotificationLevelIndicator of whether notifications for all messages are enabled by default in the guild.
explicit_content_filter: ExplicitContentFilterDefault explicit content filter level.
roles: HashMap<RoleId, Role>A mapping of the guild’s roles.
emojis: HashMap<EmojiId, Emoji>All of the guild’s custom emojis.
features: Vec<String>The guild features. These are user-invisible options which are used for Discord rollouts
and/or paid benefits. More information is available at discord's documentation.
mfa_level: MfaLevelIndicator of whether the guild requires multi-factor authentication for Roles or
Users with moderation permissions.
application_id: Option<ApplicationId>Application ID of the guild creator if it is bot-created.
system_channel_id: Option<ChannelId>The ID of the channel to which system messages are sent.
system_channel_flags: SystemChannelFlagsSystem 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.
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.
vanity_url_code: Option<String>The vanity url code for the guild, if it has one.
description: Option<String>The server’s description, if it has one.
The guild’s banner, if it has one.
The server’s premium boosting level.
The total number of users currently boosting this server.
preferred_locale: StringThe preferred locale of this guild only set if guild has the “COMMUNITY” feature, defaults to en-US.
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.
max_video_channel_users: Option<u64>The maximum amount of users in a video channel.
max_stage_video_channel_users: Option<u64>The maximum amount of users in a stage video channel
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.
welcome_screen: Option<GuildWelcomeScreen>The welcome screen of the guild.
Note: Only available on COMMUNITY guild, see Self::features.
nsfw_level: NsfwLevelThe guild NSFW state. See discord support article.
stickers: HashMap<StickerId, Sticker>All of the guild’s custom stickers.
Whether the guild has the boost progress bar enabled
joined_at: TimestampThe date that the current user joined the guild.
large: boolIndicator of whether the guild is considered “large” by Discord.
Whether this guild is unavailable due to an outage.
member_count: u64The number of members in the guild.
voice_states: HashMap<UserId, VoiceState>A mapping of Users to their current voice state.
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.
channels: HashMap<ChannelId, GuildChannel>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).
threads: Vec<GuildChannel>All active threads in this guild that current user has permission to view.
A thread is guaranteed (for errors, not for panics) to be cached if a MESSAGE_CREATE
event is fired in said thread, however an INTERACTION_CREATE may not have a private
thread in cache.
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.
stage_instances: Vec<StageInstance>The stage instances in this guild.
scheduled_events: Vec<ScheduledEvent>The stage instances in this guild.
safety_alerts_channel_id: Option<ChannelId>The id of the channel where this guild will recieve safety alerts.
incidents_data: Option<IncidentsData>The incidents data for this guild, if any.
Implementations§
Source§impl Guild
impl Guild
Sourcepub async fn automod_rules(&self, http: impl AsRef<Http>) -> Result<Vec<Rule>>
Available on crate feature model only.
pub async fn automod_rules(&self, http: impl AsRef<Http>) -> Result<Vec<Rule>>
model only.Gets all auto moderation Rules of this guild via HTTP.
Note: Requires the Manage Guild permission.
§Errors
Returns an Error::Http if the guild is unavailable.
Sourcepub async fn automod_rule(
&self,
http: impl AsRef<Http>,
rule_id: impl Into<RuleId>,
) -> Result<Rule>
Available on crate feature model only.
pub async fn automod_rule( &self, http: impl AsRef<Http>, rule_id: impl Into<RuleId>, ) -> Result<Rule>
model only.Gets an auto moderation Rule of this guild by its ID via HTTP.
Note: Requires the Manage Guild permission.
§Errors
Returns an Error::Http if a rule with the given ID does not exist.
Sourcepub async fn create_automod_rule(
&self,
cache_http: impl CacheHttp,
builder: EditAutoModRule<'_>,
) -> Result<Rule>
Available on crate feature model only.
pub async fn create_automod_rule( &self, cache_http: impl CacheHttp, builder: EditAutoModRule<'_>, ) -> Result<Rule>
model only.Creates an auto moderation Rule in the guild.
Note: Requires the Manage Guild permission.
§Examples
See GuildId::create_automod_rule for details.
§Errors
Returns Error::Http if the current user lacks permission, or if invalid data is given.
Sourcepub async fn edit_automod_rule(
&self,
cache_http: impl CacheHttp,
rule_id: impl Into<RuleId>,
builder: EditAutoModRule<'_>,
) -> Result<Rule>
Available on crate feature model only.
pub async fn edit_automod_rule( &self, cache_http: impl CacheHttp, rule_id: impl Into<RuleId>, builder: EditAutoModRule<'_>, ) -> Result<Rule>
model only.Edit an auto moderation Rule, given its Id.
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http if the current user lacks permission, or if invalid data is given.
Sourcepub async fn delete_automod_rule(
&self,
http: impl AsRef<Http>,
rule_id: impl Into<RuleId>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_automod_rule( &self, http: impl AsRef<Http>, rule_id: impl Into<RuleId>, ) -> Result<()>
model only.Deletes an auto moderation Rule from the guild.
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http if the current user lacks permission, or if a rule with that Id
does not exist.
Sourcepub fn default_channel(&self, uid: UserId) -> Option<&GuildChannel>
Available on crate feature model only.
pub fn default_channel(&self, uid: UserId) -> Option<&GuildChannel>
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)
Sourcepub fn default_channel_guaranteed(&self) -> Option<&GuildChannel>
Available on crate feature model only.
pub fn default_channel_guaranteed(&self) -> Option<&GuildChannel>
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.
pub fn channel_id_from_name( &self, cache: impl AsRef<Cache>, name: impl AsRef<str>, ) -> Option<ChannelId>
model and cache only.Sourcepub async fn ban(
&self,
cache_http: impl CacheHttp,
user: impl Into<UserId>,
dmd: u8,
) -> Result<()>
Available on crate feature model only.
pub async fn ban( &self, cache_http: impl CacheHttp, user: impl Into<UserId>, dmd: u8, ) -> Result<()>
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.
Sourcepub async fn ban_with_reason(
&self,
cache_http: impl CacheHttp,
user: impl Into<UserId>,
dmd: u8,
reason: impl AsRef<str>,
) -> Result<()>
Available on crate feature model only.
pub async fn ban_with_reason( &self, cache_http: impl CacheHttp, user: impl Into<UserId>, dmd: u8, reason: impl AsRef<str>, ) -> Result<()>
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.
Sourcepub async fn bulk_ban(
&self,
cache_http: impl CacheHttp,
user_ids: &[UserId],
delete_message_seconds: u32,
reason: Option<&str>,
) -> Result<BulkBanResponse>
Available on crate feature model only.
pub async fn bulk_ban( &self, cache_http: impl CacheHttp, user_ids: &[UserId], delete_message_seconds: u32, reason: Option<&str>, ) -> Result<BulkBanResponse>
model only.Bans multiple users from the guild, returning the users that were and weren’t banned.
§Errors
See GuildId::bulk_ban for more information.
Available on crate feature model only.
model only.Returns the formatted URL of the guild’s banner image, if one exists.
Sourcepub async fn bans(
&self,
cache_http: impl CacheHttp,
target: Option<UserPagination>,
limit: Option<u8>,
) -> Result<Vec<Ban>>
Available on crate feature model only.
pub async fn bans( &self, cache_http: impl CacheHttp, target: Option<UserPagination>, limit: Option<u8>, ) -> Result<Vec<Ban>>
model only.Gets a list of the guild’s bans, with additional options and filtering. See
Http::get_bans for details.
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.
Sourcepub async fn get_ban(
&self,
cache_http: impl CacheHttp,
user_id: UserId,
) -> Result<Option<Ban>>
Available on crate feature model only.
pub async fn get_ban( &self, cache_http: impl CacheHttp, user_id: UserId, ) -> Result<Option<Ban>>
model only.Gets a user’s ban from the guild.
See Http::get_bans for details.
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.
Sourcepub async fn add_member(
&self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
builder: AddMember,
) -> Result<Option<Member>>
Available on crate feature model only.
pub async fn add_member( &self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, builder: AddMember, ) -> Result<Option<Member>>
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 data is given.
Sourcepub async fn audit_logs(
&self,
http: impl AsRef<Http>,
action_type: Option<Action>,
user_id: Option<UserId>,
before: Option<AuditLogEntryId>,
limit: Option<u8>,
) -> Result<AuditLogs>
Available on crate feature model only.
pub async fn audit_logs( &self, http: impl AsRef<Http>, action_type: Option<Action>, user_id: Option<UserId>, before: Option<AuditLogEntryId>, limit: Option<u8>, ) -> Result<AuditLogs>
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.
Sourcepub async fn channels(
&self,
http: impl AsRef<Http>,
) -> Result<HashMap<ChannelId, GuildChannel>>
Available on crate feature model only.
pub async fn channels( &self, http: impl AsRef<Http>, ) -> Result<HashMap<ChannelId, GuildChannel>>
model only.Gets all of the guild’s channels over the REST API.
§Errors
Returns Error::Http if the guild is currently unavailable.
Sourcepub async fn create(
http: impl AsRef<Http>,
name: &str,
icon: Option<ImageHash>,
) -> Result<PartialGuild>
👎Deprecated: This endpoint has been deprecated by Discord and will stop functioning after July 15, 2025. For more information, see: https://discord.com/developers/docs/change-log#deprecating-guild-creation-by-appsAvailable on crate feature model only.
pub async fn create( http: impl AsRef<Http>, name: &str, icon: Option<ImageHash>, ) -> Result<PartialGuild>
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.
Sourcepub async fn create_channel(
&self,
cache_http: impl CacheHttp,
builder: CreateChannel<'_>,
) -> Result<GuildChannel>
Available on crate feature model only.
pub async fn create_channel( &self, cache_http: impl CacheHttp, builder: CreateChannel<'_>, ) -> Result<GuildChannel>
model only.Creates a new Channel in the guild.
Note: Requires the Manage Channels permission.
§Examples
use serenity::builder::CreateChannel;
use serenity::model::channel::ChannelType;
let builder = CreateChannel::new("my-test-channel").kind(ChannelType::Text);
// assuming a `guild` has already been bound
let _channel = guild.create_channel(&http, builder).await?;§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn create_emoji(
&self,
http: impl AsRef<Http>,
name: &str,
image: &str,
) -> Result<Emoji>
Available on crate feature model only.
pub async fn create_emoji( &self, http: impl AsRef<Http>, name: &str, image: &str, ) -> Result<Emoji>
model only.Creates an emoji in the guild with a name and base64-encoded image. The
CreateAttachment builder 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 Create Guild Expressions 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.
Sourcepub async fn create_integration(
&self,
http: impl AsRef<Http>,
integration_id: impl Into<IntegrationId>,
kind: &str,
) -> Result<()>
Available on crate feature model only.
pub async fn create_integration( &self, http: impl AsRef<Http>, integration_id: impl Into<IntegrationId>, kind: &str, ) -> Result<()>
model only.Creates an integration for the guild.
Requires the Manage Guild permission.
§Errors
Returns Error::Http if the current user lacks permission.
Sourcepub async fn create_command(
&self,
cache_http: impl CacheHttp,
builder: CreateCommand,
) -> Result<Command>
Available on crate feature model only.
pub async fn create_command( &self, cache_http: impl CacheHttp, builder: CreateCommand, ) -> Result<Command>
model only.Create a guild specific application Command.
Note: Unlike global commands, guild commands will update instantly.
§Errors
See CreateCommand::execute for a list of possible errors.
Sourcepub async fn set_commands(
&self,
http: impl AsRef<Http>,
commands: Vec<CreateCommand>,
) -> Result<Vec<Command>>
Available on crate feature model only.
pub async fn set_commands( &self, http: impl AsRef<Http>, commands: Vec<CreateCommand>, ) -> Result<Vec<Command>>
model only.Sourcepub async fn edit_command_permissions(
&self,
cache_http: impl CacheHttp,
command_id: CommandId,
builder: EditCommandPermissions,
) -> Result<CommandPermissions>
Available on crate feature model only.
pub async fn edit_command_permissions( &self, cache_http: impl CacheHttp, command_id: CommandId, builder: EditCommandPermissions, ) -> Result<CommandPermissions>
model only.Overwrites permissions for a specific command.
Note: It will update instantly.
§Errors
See CreateCommandPermissionsData::execute for a list of possible errors.
Sourcepub async fn get_commands(&self, http: impl AsRef<Http>) -> Result<Vec<Command>>
Available on crate feature model only.
pub async fn get_commands(&self, http: impl AsRef<Http>) -> Result<Vec<Command>>
model only.Get all guild application commands.
§Errors
If there is an error, it will be either Error::Http or Error::Json.
Sourcepub async fn get_commands_with_localizations(
&self,
http: impl AsRef<Http>,
) -> Result<Vec<Command>>
Available on crate feature model only.
pub async fn get_commands_with_localizations( &self, http: impl AsRef<Http>, ) -> Result<Vec<Command>>
model only.Get all guild application commands with localizations.
§Errors
If there is an error, it will be either Error::Http or Error::Json.
Sourcepub async fn get_command(
&self,
http: impl AsRef<Http>,
command_id: CommandId,
) -> Result<Command>
Available on crate feature model only.
pub async fn get_command( &self, http: impl AsRef<Http>, command_id: CommandId, ) -> Result<Command>
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.
Sourcepub async fn edit_command(
&self,
cache_http: impl CacheHttp,
command_id: CommandId,
builder: CreateCommand,
) -> Result<Command>
Available on crate feature model only.
pub async fn edit_command( &self, cache_http: impl CacheHttp, command_id: CommandId, builder: CreateCommand, ) -> Result<Command>
model only.Edit a guild application command, given its Id.
§Errors
See CreateCommand::execute for a list of possible errors.
Sourcepub async fn delete_command(
&self,
http: impl AsRef<Http>,
command_id: CommandId,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_command( &self, http: impl AsRef<Http>, command_id: CommandId, ) -> Result<()>
model only.Delete guild application command by its Id.
§Errors
If there is an error, it will be either Error::Http or Error::Json.
Sourcepub async fn get_commands_permissions(
&self,
http: impl AsRef<Http>,
) -> Result<Vec<CommandPermissions>>
Available on crate feature model only.
pub async fn get_commands_permissions( &self, http: impl AsRef<Http>, ) -> Result<Vec<CommandPermissions>>
model only.Get all guild application commands permissions only.
§Errors
If there is an error, it will be either Error::Http or Error::Json.
Sourcepub async fn get_command_permissions(
&self,
http: impl AsRef<Http>,
command_id: CommandId,
) -> Result<CommandPermissions>
Available on crate feature model only.
pub async fn get_command_permissions( &self, http: impl AsRef<Http>, command_id: CommandId, ) -> Result<CommandPermissions>
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.
Sourcepub async fn create_role(
&self,
cache_http: impl CacheHttp,
builder: EditRole<'_>,
) -> Result<Role>
Available on crate feature model only.
pub async fn create_role( &self, cache_http: impl CacheHttp, builder: EditRole<'_>, ) -> Result<Role>
model only.Creates a new role in the guild with the data set, if any.
Note: Requires the Manage Roles permission.
§Examples
See the documentation for EditRole for details.
§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn create_scheduled_event(
&self,
cache_http: impl CacheHttp,
builder: CreateScheduledEvent<'_>,
) -> Result<ScheduledEvent>
Available on crate feature model only.
pub async fn create_scheduled_event( &self, cache_http: impl CacheHttp, builder: CreateScheduledEvent<'_>, ) -> Result<ScheduledEvent>
model only.Creates a new scheduled event in the guild with the data set, if any.
Note: Requires the Create Events permission.
§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn create_sticker(
&self,
cache_http: impl CacheHttp,
builder: CreateSticker<'_>,
) -> Result<Sticker>
Available on crate feature model only.
pub async fn create_sticker( &self, cache_http: impl CacheHttp, builder: CreateSticker<'_>, ) -> Result<Sticker>
model only.Creates a new sticker in the guild with the data set, if any.
Note: Requires the Create Guild Expressions permission.
§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()>
Available on crate feature model only.
pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()>
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.
Sourcepub async fn delete_emoji(
&self,
http: impl AsRef<Http>,
emoji_id: impl Into<EmojiId>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_emoji( &self, http: impl AsRef<Http>, emoji_id: impl Into<EmojiId>, ) -> Result<()>
model only.Deletes an Emoji from the guild.
Note: If the emoji was created by the current user, requires either the Create Guild Expressions or the Manage Guild Expressions permission. Otherwise, the Manage Guild Expressions permission is required.
§Errors
Returns Error::Http if the current user lacks permission, or if an emoji with the given
id does not exist in the guild.
Sourcepub async fn delete_integration(
&self,
http: impl AsRef<Http>,
integration_id: impl Into<IntegrationId>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_integration( &self, http: impl AsRef<Http>, integration_id: impl Into<IntegrationId>, ) -> Result<()>
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.
Sourcepub async fn delete_role(
&self,
http: impl AsRef<Http>,
role_id: impl Into<RoleId>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_role( &self, http: impl AsRef<Http>, role_id: impl Into<RoleId>, ) -> Result<()>
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.
Sourcepub async fn delete_scheduled_event(
&self,
http: impl AsRef<Http>,
event_id: impl Into<ScheduledEventId>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_scheduled_event( &self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, ) -> Result<()>
model only.Deletes a ScheduledEvent by id from the guild.
Note: If the event was created by the current user, requires either Create Events or the Manage Events permission. Otherwise, the Manage Events permission is required.
§Errors
Returns Error::Http if the current user lacks permission to delete the scheduled event.
Sourcepub async fn delete_sticker(
&self,
http: impl AsRef<Http>,
sticker_id: impl Into<StickerId>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_sticker( &self, http: impl AsRef<Http>, sticker_id: impl Into<StickerId>, ) -> Result<()>
model only.Deletes a Sticker by Id from the guild.
Note: If the sticker was created by the current user, requires either the Create Guild Expressions or the Manage Guild Expressions permission. Otherwise, the Manage Guild Expressions permission is required.
§Errors
Returns Error::Http if the current user lacks permission, or if a sticker with that id
does not exist.
Sourcepub async fn edit(
&mut self,
cache_http: impl CacheHttp,
builder: EditGuild<'_>,
) -> Result<()>
Available on crate feature model only.
pub async fn edit( &mut self, cache_http: impl CacheHttp, builder: EditGuild<'_>, ) -> Result<()>
model only.Edits the current guild with new data where specified.
Note: Requires the Manage Guild permission.
§Examples
Change a guild’s icon using a file named “icon.png”:
let icon = CreateAttachment::path("./icon.png").await?;
// assuming a `guild` has already been bound
let builder = EditGuild::new().icon(Some(&icon));
guild.edit(&http, builder).await?;§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn edit_emoji(
&self,
http: impl AsRef<Http>,
emoji_id: impl Into<EmojiId>,
name: &str,
) -> Result<Emoji>
Available on crate feature model only.
pub async fn edit_emoji( &self, http: impl AsRef<Http>, emoji_id: impl Into<EmojiId>, name: &str, ) -> Result<Emoji>
model only.Edits an Emoji’s name in the guild.
Also see Emoji::edit if you have the cache and model features enabled.
Note: If the emoji was created by the current user, requires either the Create Guild Expressions or the Manage Guild Expressions permission. Otherwise, the Manage Guild Expressions permission is required.
§Errors
Returns Error::Http if the current user lacks permission, or if an emoji with the given
id does not exist.
Sourcepub async fn edit_member(
&self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
builder: EditMember<'_>,
) -> Result<Member>
Available on crate feature model only.
pub async fn edit_member( &self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, builder: EditMember<'_>, ) -> Result<Member>
model only.Edits the properties a guild member, such as muting or nicknaming them. Returns the new member.
Refer to the documentation of EditMember for a full list of methods and permission
restrictions.
§Examples
See GuildId::edit_member for details.
§Errors
Returns Error::Http if the current user lacks permission, or if invalid data is given.
Sourcepub async fn edit_mfa_level(
&self,
http: impl AsRef<Http>,
mfa_level: MfaLevel,
audit_log_reason: Option<&str>,
) -> Result<MfaLevel>
Available on crate feature model only.
pub async fn edit_mfa_level( &self, http: impl AsRef<Http>, mfa_level: MfaLevel, audit_log_reason: Option<&str>, ) -> Result<MfaLevel>
model only.Edits the guild’s MFA level. Returns the new level on success.
Requires guild ownership.
§Errors
Returns Error::Http if the current user lacks permission.
Sourcepub async fn edit_nickname(
&self,
cache_http: impl CacheHttp,
new_nickname: Option<&str>,
) -> Result<()>
Available on crate feature model only.
pub async fn edit_nickname( &self, cache_http: impl CacheHttp, new_nickname: Option<&str>, ) -> Result<()>
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.
Sourcepub async fn edit_role(
&self,
cache_http: impl CacheHttp,
role_id: impl Into<RoleId>,
builder: EditRole<'_>,
) -> Result<Role>
Available on crate feature model only.
pub async fn edit_role( &self, cache_http: impl CacheHttp, role_id: impl Into<RoleId>, builder: EditRole<'_>, ) -> Result<Role>
model only.Edits a role, optionally setting its fields.
Note: Requires the Manage Roles permission.
§Examples
See the documentation of GuildId::edit_role for details.
§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn edit_role_position(
&self,
http: impl AsRef<Http>,
role_id: impl Into<RoleId>,
position: u16,
) -> Result<Vec<Role>>
Available on crate feature model only.
pub async fn edit_role_position( &self, http: impl AsRef<Http>, role_id: impl Into<RoleId>, position: u16, ) -> Result<Vec<Role>>
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::new(8), 2);§Errors
Returns Error::Http if the current user lacks permission.
Sourcepub async fn edit_scheduled_event(
&self,
cache_http: impl CacheHttp,
event_id: impl Into<ScheduledEventId>,
builder: EditScheduledEvent<'_>,
) -> Result<ScheduledEvent>
Available on crate feature model only.
pub async fn edit_scheduled_event( &self, cache_http: impl CacheHttp, event_id: impl Into<ScheduledEventId>, builder: EditScheduledEvent<'_>, ) -> Result<ScheduledEvent>
model only.Modifies a scheduled event in the guild with the data set, if any.
Note: If the event was created by the current user, requires either Create Events or the Manage Events permission. Otherwise, the Manage Events permission is required.
§Errors
If the cache is enabled, returns a ModelError::InvalidPermissions if the current user
lacks permission. Otherwise returns Error::Http, as well as if invalid data is given.
Sourcepub async fn edit_sticker(
&self,
cache_http: impl CacheHttp,
sticker_id: impl Into<StickerId>,
builder: EditSticker<'_>,
) -> Result<Sticker>
Available on crate feature model only.
pub async fn edit_sticker( &self, cache_http: impl CacheHttp, sticker_id: impl Into<StickerId>, builder: EditSticker<'_>, ) -> Result<Sticker>
model only.Edits a sticker.
Note: If the sticker was created by the current user, requires either the Create Guild Expressions or the Manage Guild Expressions permission. Otherwise, the Manage Guild Expressions permission is required.
§Examples
Rename a sticker:
use serenity::builder::EditSticker;
use serenity::model::id::StickerId;
let builder = EditSticker::new().name("Bun bun meow");
guild.edit_sticker(&http, StickerId::new(7), builder).await?;§Errors
Returns Error::Http if the current user lacks permission, or if invalid data is given.
Sourcepub async fn edit_welcome_screen(
&self,
cache_http: impl CacheHttp,
builder: EditGuildWelcomeScreen<'_>,
) -> Result<GuildWelcomeScreen>
Available on crate feature model only.
pub async fn edit_welcome_screen( &self, cache_http: impl CacheHttp, builder: EditGuildWelcomeScreen<'_>, ) -> Result<GuildWelcomeScreen>
model only.Edits the guild’s welcome screen.
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http if the current user lacks permission.
Sourcepub async fn edit_widget(
&self,
cache_http: impl CacheHttp,
builder: EditGuildWidget<'_>,
) -> Result<GuildWidget>
Available on crate feature model only.
pub async fn edit_widget( &self, cache_http: impl CacheHttp, builder: EditGuildWidget<'_>, ) -> Result<GuildWidget>
model only.Edits the guild’s widget.
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http if the current user lacks permission.
Sourcepub async fn get(
cache_http: impl CacheHttp,
guild_id: impl Into<GuildId>,
) -> Result<PartialGuild>
Available on crate feature model only.
pub async fn get( cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, ) -> Result<PartialGuild>
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.
Sourcepub fn member_highest_role(&self, member: &Member) -> Option<&Role>
Available on crate feature model only.
pub fn member_highest_role(&self, member: &Member) -> Option<&Role>
model only.Gets the highest role a Member of this Guild has.
Returns None if the member has no roles or the member from this guild.
Sourcepub fn greater_member_hierarchy(
&self,
_cache: impl AsRef<Cache>,
lhs_id: impl Into<UserId>,
rhs_id: impl Into<UserId>,
) -> Option<UserId>
Available on crate features model and cache only.
pub fn greater_member_hierarchy( &self, _cache: impl AsRef<Cache>, lhs_id: impl Into<UserId>, rhs_id: impl Into<UserId>, ) -> Option<UserId>
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.
Sourcepub fn icon_url(&self) -> Option<String>
Available on crate feature model only.
pub fn icon_url(&self) -> Option<String>
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.
Sourcepub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>>
Available on crate feature model only.
pub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>>
model only.Sourcepub async fn emoji(
&self,
http: impl AsRef<Http>,
emoji_id: EmojiId,
) -> Result<Emoji>
Available on crate feature model only.
pub async fn emoji( &self, http: impl AsRef<Http>, emoji_id: EmojiId, ) -> Result<Emoji>
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 deserializing the API response.
Sourcepub async fn integrations(
&self,
http: impl AsRef<Http>,
) -> Result<Vec<Integration>>
Available on crate feature model only.
pub async fn integrations( &self, http: impl AsRef<Http>, ) -> Result<Vec<Integration>>
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.
Sourcepub async fn invites(
&self,
cache_http: impl CacheHttp,
) -> Result<Vec<RichInvite>>
Available on crate feature model only.
pub async fn invites( &self, cache_http: impl CacheHttp, ) -> Result<Vec<RichInvite>>
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.
Sourcepub fn is_large(&self) -> bool
👎Deprecated: Use Guild::largeAvailable on crate feature model only.
pub fn is_large(&self) -> bool
model only.Checks if the guild is ‘large’.
A guild is considered large if it has more than 250 members.
Sourcepub async fn kick(
&self,
http: impl AsRef<Http>,
user_id: impl Into<UserId>,
) -> Result<()>
Available on crate feature model only.
pub async fn kick( &self, http: impl AsRef<Http>, user_id: impl Into<UserId>, ) -> Result<()>
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.
Sourcepub async fn kick_with_reason(
&self,
http: impl AsRef<Http>,
user_id: impl Into<UserId>,
reason: &str,
) -> Result<()>
Available on crate feature model only.
pub async fn kick_with_reason( &self, http: impl AsRef<Http>, user_id: impl Into<UserId>, reason: &str, ) -> Result<()>
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.
Sourcepub async fn current_user_member(
&self,
http: impl AsRef<Http>,
) -> Result<Member>
Available on crate feature model only.
pub async fn current_user_member( &self, http: impl AsRef<Http>, ) -> Result<Member>
model only.Returns a guild Member object for the current user.
See Http::get_current_user_guild_member for more.
§Errors
Returns an Error::Http if the current user is not in the guild or the access token
lacks the necessary scope.
Sourcepub async fn leave(&self, http: impl AsRef<Http>) -> Result<()>
Available on crate feature model only.
pub async fn leave(&self, http: impl AsRef<Http>) -> Result<()>
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.
Sourcepub async fn member(
&self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
) -> Result<Cow<'_, Member>>
Available on crate feature model only.
pub async fn member( &self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, ) -> Result<Cow<'_, Member>>
model only.Gets a user’s Member for the guild by Id.
If the cache feature is enabled Self::members will be checked first, if so, a reference
to the member will be returned.
§Errors
Returns an Error::Http if the user is not in the guild or if the guild is otherwise
unavailable.
Sourcepub async fn members(
&self,
http: impl AsRef<Http>,
limit: Option<u64>,
after: impl Into<Option<UserId>>,
) -> Result<Vec<Member>>
Available on crate feature model only.
pub async fn members( &self, http: impl AsRef<Http>, limit: Option<u64>, after: impl Into<Option<UserId>>, ) -> Result<Vec<Member>>
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.
Sourcepub fn members_with_status(
&self,
status: OnlineStatus,
) -> impl Iterator<Item = &Member>
Available on crate feature model only.
pub fn members_with_status( &self, status: OnlineStatus, ) -> impl Iterator<Item = &Member>
model only.Gets a list of all the members (satisfying the status provided to the function) in this guild.
Sourcepub fn member_named(&self, name: &str) -> Option<&Member>
Available on crate feature model only.
pub fn member_named(&self, name: &str) -> Option<&Member>
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.
Sourcepub fn members_starting_with(
&self,
prefix: &str,
case_sensitive: bool,
sorted: bool,
) -> Vec<(&Member, String)>
Available on crate feature model only.
pub fn members_starting_with( &self, prefix: &str, case_sensitive: bool, sorted: bool, ) -> Vec<(&Member, String)>
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”
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.
Sourcepub fn members_containing(
&self,
substring: &str,
case_sensitive: bool,
sorted: bool,
) -> Vec<(&Member, String)>
Available on crate feature model only.
pub fn members_containing( &self, substring: &str, case_sensitive: bool, sorted: bool, ) -> Vec<(&Member, String)>
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.
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.
Sourcepub fn members_username_containing(
&self,
substring: &str,
case_sensitive: bool,
sorted: bool,
) -> Vec<(&Member, String)>
Available on crate feature model only.
pub fn members_username_containing( &self, substring: &str, case_sensitive: bool, sorted: bool, ) -> Vec<(&Member, String)>
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”
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.
Sourcepub fn members_nick_containing(
&self,
substring: &str,
case_sensitive: bool,
sorted: bool,
) -> Vec<(&Member, String)>
Available on crate feature model only.
pub fn members_nick_containing( &self, substring: &str, case_sensitive: bool, sorted: bool, ) -> Vec<(&Member, String)>
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).
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.
Sourcepub fn member_permissions(&self, member: &Member) -> Permissions
Available on crate feature model only.
pub fn member_permissions(&self, member: &Member) -> Permissions
model only.Calculate a Member’s permissions in the guild.
You likely want to use Guild::user_permissions_in instead as this function does not consider permission overwrites.
Sourcepub fn partial_member_permissions(
&self,
member_id: UserId,
member: &PartialMember,
) -> Permissions
Available on crate feature model only.
pub fn partial_member_permissions( &self, member_id: UserId, member: &PartialMember, ) -> Permissions
model only.Calculate a PartialMember’s permissions in the guild.
You likely want to use Guild::partial_member_permissions_in instead as this function does not consider permission overwrites.
§Panics
Panics if the passed UserId does not match the PartialMember id, if user is Some.
Sourcepub async fn move_member(
&self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
channel_id: impl Into<ChannelId>,
) -> Result<Member>
Available on crate feature model only.
pub async fn move_member( &self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, channel_id: impl Into<ChannelId>, ) -> Result<Member>
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.
Sourcepub fn user_permissions_in(
&self,
channel: &GuildChannel,
member: &Member,
) -> Permissions
Available on crate feature model only.
pub fn user_permissions_in( &self, channel: &GuildChannel, member: &Member, ) -> Permissions
model only.Calculate a Member’s permissions in a given channel in the guild.
Sourcepub fn partial_member_permissions_in(
&self,
channel: &GuildChannel,
member_id: UserId,
member: &PartialMember,
) -> Permissions
Available on crate feature model only.
pub fn partial_member_permissions_in( &self, channel: &GuildChannel, member_id: UserId, member: &PartialMember, ) -> Permissions
model only.Calculate a PartialMember’s permissions in a given channel in a guild.
§Panics
Panics if the passed UserId does not match the PartialMember id, if user is Some.
Sourcepub fn role_permissions_in(
&self,
channel: &GuildChannel,
role: &Role,
) -> Result<Permissions>
👎Deprecated: this function ignores other roles the user may have as well as user-specific permissions; use user_permissions_in insteadAvailable on crate feature model only.
pub fn role_permissions_in( &self, channel: &GuildChannel, role: &Role, ) -> Result<Permissions>
model only.Sourcepub async fn prune_count(
&self,
cache_http: impl CacheHttp,
days: u8,
) -> Result<GuildPrune>
Available on crate feature model only.
pub async fn prune_count( &self, cache_http: impl CacheHttp, days: u8, ) -> Result<GuildPrune>
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.
Sourcepub async fn reorder_channels(
&self,
http: impl AsRef<Http>,
channels: impl IntoIterator<Item = (ChannelId, u64)>,
) -> Result<()>
Available on crate feature model only.
pub async fn reorder_channels( &self, http: impl AsRef<Http>, channels: impl IntoIterator<Item = (ChannelId, u64)>, ) -> Result<()>
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.
Sourcepub async fn search_members(
&self,
http: impl AsRef<Http>,
query: &str,
limit: Option<u64>,
) -> Result<Vec<Member>>
Available on crate feature model only.
pub async fn search_members( &self, http: impl AsRef<Http>, query: &str, limit: Option<u64>, ) -> Result<Vec<Member>>
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.
Sourcepub async fn scheduled_event(
&self,
http: impl AsRef<Http>,
event_id: impl Into<ScheduledEventId>,
with_user_count: bool,
) -> Result<ScheduledEvent>
Available on crate feature model only.
pub async fn scheduled_event( &self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, with_user_count: bool, ) -> Result<ScheduledEvent>
model only.Fetches a specified 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: Requires the View Channel permission for the channel associated with the event.
§Errors
Returns Error::Http if the current user lacks permission, or if the provided id is
invalid.
Sourcepub async fn scheduled_events(
&self,
http: impl AsRef<Http>,
with_user_count: bool,
) -> Result<Vec<ScheduledEvent>>
Available on crate feature model only.
pub async fn scheduled_events( &self, http: impl AsRef<Http>, with_user_count: bool, ) -> Result<Vec<ScheduledEvent>>
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: Requires the View Channel permission at the guild level.
§Errors
Returns Error::Http if the current user lacks permission.
Sourcepub async fn scheduled_event_users(
&self,
http: impl AsRef<Http>,
event_id: impl Into<ScheduledEventId>,
limit: Option<u64>,
) -> Result<Vec<ScheduledEventUser>>
Available on crate feature model only.
pub async fn scheduled_event_users( &self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, limit: Option<u64>, ) -> Result<Vec<ScheduledEventUser>>
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 View Channel permission for the channel associated with the event.
§Errors
Returns Error::Http if the current user lacks permission, or if the provided Id is
invalid.
Sourcepub async fn scheduled_event_users_optioned(
&self,
http: impl AsRef<Http>,
event_id: impl Into<ScheduledEventId>,
limit: Option<u64>,
target: Option<UserPagination>,
with_member: Option<bool>,
) -> Result<Vec<ScheduledEventUser>>
Available on crate feature model only.
pub async fn scheduled_event_users_optioned( &self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, limit: Option<u64>, target: Option<UserPagination>, with_member: Option<bool>, ) -> Result<Vec<ScheduledEventUser>>
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 View Channel permission for the channel associated with the event.
§Errors
Returns Error::Http if the current user lacks permission, or if the provided Id is
invalid.
Sourcepub fn shard_id(&self, cache: impl AsRef<Cache>) -> u32
Available on crate features cache and utils and model only.
pub fn shard_id(&self, cache: impl AsRef<Cache>) -> u32
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.
Sourcepub fn splash_url(&self) -> Option<String>
Available on crate feature model only.
pub fn splash_url(&self) -> Option<String>
model only.Returns the formatted URL of the guild’s splash image, if one exists.
Sourcepub async fn start_integration_sync(
&self,
http: impl AsRef<Http>,
integration_id: impl Into<IntegrationId>,
) -> Result<()>
Available on crate feature model only.
pub async fn start_integration_sync( &self, http: impl AsRef<Http>, integration_id: impl Into<IntegrationId>, ) -> Result<()>
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.
Sourcepub async fn start_prune(
&self,
cache_http: impl CacheHttp,
days: u8,
) -> Result<GuildPrune>
Available on crate feature model only.
pub async fn start_prune( &self, cache_http: impl CacheHttp, days: u8, ) -> Result<GuildPrune>
model only.Starts a prune of Members.
See the documentation on GuildPrune for more information.
Note: Requires Kick Members and Manage Guild permissions.
§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.
Sourcepub async fn unban(
&self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
) -> Result<()>
Available on crate feature model only.
pub async fn unban( &self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, ) -> Result<()>
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.
Sourcepub async fn vanity_url(&self, http: impl AsRef<Http>) -> Result<String>
Available on crate feature model only.
pub async fn vanity_url(&self, http: impl AsRef<Http>) -> Result<String>
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.
Sourcepub async fn webhooks(&self, http: impl AsRef<Http>) -> Result<Vec<Webhook>>
Available on crate feature model only.
pub async fn webhooks(&self, http: impl AsRef<Http>) -> Result<Vec<Webhook>>
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.
Sourcepub fn role_by_name(&self, role_name: &str) -> Option<&Role>
Available on crate feature model only.
pub fn role_by_name(&self, role_name: &str) -> Option<&Role>
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.
#[serenity::async_trait]
#[cfg(all(feature = "cache", feature = "client"))]
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);
}
}
}
}
}Sourcepub fn await_reply(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
Available on crate features model and collector only.
pub fn await_reply( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
model and collector only.Returns a builder which can be awaited to obtain a message or stream of messages in this guild.
Sourcepub fn await_replies(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
Available on crate features model and collector only.
pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
model and collector only.Same as Self::await_reply.
Sourcepub fn await_reaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
Available on crate features model and collector only.
pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
model and collector only.Returns a builder which can be awaited to obtain a message or stream of reactions sent in this guild.
Sourcepub fn await_reactions(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
Available on crate features model and collector only.
pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
model and collector only.Same as Self::await_reaction.
Sourcepub async fn get_active_threads(
&self,
http: impl AsRef<Http>,
) -> Result<ThreadsData>
Available on crate feature model only.
pub async fn get_active_threads( &self, http: impl AsRef<Http>, ) -> Result<ThreadsData>
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.
Sourcepub async fn get_soundboard(
self,
http: impl AsRef<Http>,
sound_id: SoundId,
) -> Result<Soundboard>
Available on crate feature model only.
pub async fn get_soundboard( self, http: impl AsRef<Http>, sound_id: SoundId, ) -> Result<Soundboard>
model only.Gets a soundboard sound from the guild.
§Errors
Returns Error::Http if there is an error in the deserialization, or if the bot issuing
the request is not in the guild.
Sourcepub async fn get_soundboards(
self,
http: impl AsRef<Http>,
) -> Result<Vec<Soundboard>>
Available on crate feature model only.
pub async fn get_soundboards( self, http: impl AsRef<Http>, ) -> Result<Vec<Soundboard>>
model only.Gets all soundboard sounds from the guild.
§Errors
Returns Error::Http if there is an error in the deserialization, or if the bot issuing
the request is not in the guild.
Sourcepub async fn create_soundboard(
self,
cache_http: impl CacheHttp,
builder: CreateSoundboard<'_>,
) -> Result<Soundboard>
Available on crate feature model only.
pub async fn create_soundboard( self, cache_http: impl CacheHttp, builder: CreateSoundboard<'_>, ) -> Result<Soundboard>
model only.Creates a soundboard sound for the guild.
§Errors
See CreateSoundboard::execute for a list of possible errors.
Sourcepub async fn edit_soundboard(
self,
cache_http: impl CacheHttp,
sound_id: SoundId,
builder: EditSoundboard<'_>,
) -> Result<Soundboard>
Available on crate feature model only.
pub async fn edit_soundboard( self, cache_http: impl CacheHttp, sound_id: SoundId, builder: EditSoundboard<'_>, ) -> Result<Soundboard>
model only.Edits a soundboard sound for the guild.
§Errors
See EditSoundboard::execute for a list of possible errors.
Sourcepub async fn delete_soundboard(
self,
http: impl AsRef<Http>,
sound_id: SoundId,
audit_log_reason: Option<&str>,
) -> Result<()>
Available on crate feature model only.
pub async fn delete_soundboard( self, http: impl AsRef<Http>, sound_id: SoundId, audit_log_reason: Option<&str>, ) -> Result<()>
model only.Deletes a soundboard sound for the guild.
§Errors
Returns Error::Http if the current user lacks permission, or if a
soundboard sound with that Id does not exist.
Sourcepub async fn edit_guild_incident_actions(
self,
http: &Http,
guild_id: GuildId,
builder: EditGuildIncidentActions,
) -> Result<IncidentsData>
Available on crate feature model only.
pub async fn edit_guild_incident_actions( self, http: &Http, guild_id: GuildId, builder: EditGuildIncidentActions, ) -> Result<IncidentsData>
model only.Edits the guild incident actions
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http if invalid data is given. See Discord’s docs for more details.
May also return Error::Json if there is an error in deserializing the API response.
Trait Implementations§
Source§impl ArgumentConvert for Guild
Available on crate features cache and client and utils only.Look up a Guild, either by ID or by a string case-insensitively.
impl ArgumentConvert for Guild
cache and client and utils only.Look up a Guild, either by ID or by a string case-insensitively.
Requires the cache feature to be enabled.
Source§type Err = GuildParseError
type Err = GuildParseError
Source§fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
_guild_id: Option<GuildId>,
_channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
_guild_id: Option<GuildId>,
_channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
s as a command parameter of this type.