pub struct GuildId(/* private fields */);
Expand description
An identifier for a Guild
Implementations§
Source§impl GuildId
impl GuildId
Sourcepub async fn automod_rules(self, http: impl AsRef<Http>) -> Result<Vec<Rule>>
pub async fn automod_rules(self, http: impl AsRef<Http>) -> Result<Vec<Rule>>
Gets all auto moderation Rule
s 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>
pub async fn automod_rule( self, http: impl AsRef<Http>, rule_id: impl Into<RuleId>, ) -> Result<Rule>
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>
pub async fn create_automod_rule( self, cache_http: impl CacheHttp, builder: EditAutoModRule<'_>, ) -> Result<Rule>
Creates an auto moderation Rule
in the guild.
Note: Requires the Manage Guild permission.
§Examples
Create a custom keyword filter to block the message and timeout the author.
use std::time::Duration;
use serenity::builder::EditAutoModRule;
use serenity::model::guild::automod::{Action, Trigger};
use serenity::model::id::GuildId;
let builder = EditAutoModRule::new()
.name("foobar filter")
.trigger(Trigger::Keyword {
strings: vec!["foo*".to_string(), "*bar".to_string()],
regex_patterns: vec![],
allow_list: vec![],
})
.actions(vec![
Action::BlockMessage {
custom_message: None,
},
Action::Timeout(Duration::from_secs(60)),
]);
let _rule = GuildId::new(7).create_automod_rule(&http, builder).await;
§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>
pub async fn edit_automod_rule( self, cache_http: impl CacheHttp, rule_id: impl Into<RuleId>, builder: EditAutoModRule<'_>, ) -> Result<Rule>
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<()>
pub async fn delete_automod_rule( self, http: impl AsRef<Http>, rule_id: impl Into<RuleId>, ) -> Result<()>
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 async fn add_member(
self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
builder: AddMember,
) -> Result<Option<Member>>
pub async fn add_member( self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, builder: AddMember, ) -> Result<Option<Member>>
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 ban(
self,
http: impl AsRef<Http>,
user: impl Into<UserId>,
dmd: u8,
) -> Result<()>
pub async fn ban( self, http: impl AsRef<Http>, user: impl Into<UserId>, dmd: u8, ) -> Result<()>
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:
use serenity::model::id::{GuildId, UserId};
// assuming a `user` has already been bound
let _ = GuildId::new(81384788765712384).ban(&http, user, 4).await;
§Errors
Returns a ModelError::DeleteMessageDaysAmount
if the number of days’ worth of messages
to delete is over the maximum.
Also can return Error::Http
if the current user lacks permission.
Sourcepub async fn ban_with_reason(
self,
http: impl AsRef<Http>,
user: impl Into<UserId>,
dmd: u8,
reason: impl AsRef<str>,
) -> Result<()>
pub async fn ban_with_reason( self, http: impl AsRef<Http>, user: impl Into<UserId>, dmd: u8, reason: impl AsRef<str>, ) -> Result<()>
Ban a User
from the guild with a reason. Refer to Self::ban
to further
documentation.
§Errors
In addition to the reasons Self::ban
may return an error, may also return
Error::ExceededLimit
if reason
is too long.
Sourcepub async fn bulk_ban(
self,
http: &Http,
user_ids: &[UserId],
delete_message_seconds: u32,
reason: Option<&str>,
) -> Result<BulkBanResponse>
pub async fn bulk_ban( self, http: &Http, user_ids: &[UserId], delete_message_seconds: u32, reason: Option<&str>, ) -> Result<BulkBanResponse>
Bans multiple users from the guild, returning the users that were and weren’t banned, and
optionally deleting messages that are younger than the provided delete_message_seconds
.
§Errors
Errors if none of the users are banned or you do not have the
required BAN_MEMBERS
and MANAGE_GUILD
permissions.
Sourcepub async fn bans(
self,
http: impl AsRef<Http>,
target: Option<UserPagination>,
limit: Option<u8>,
) -> Result<Vec<Ban>>
pub async fn bans( self, http: impl AsRef<Http>, target: Option<UserPagination>, limit: Option<u8>, ) -> Result<Vec<Ban>>
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
Returns Error::Http
if the current user lacks permission.
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>
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>
Gets a list of the guild’s audit log entries
Note: Requires the View Audit Log permission.
§Errors
Returns Error::Http
if the current user lacks permission, or if an invalid value is
given.
Sourcepub async fn channels(
self,
http: impl AsRef<Http>,
) -> Result<HashMap<ChannelId, GuildChannel>>
pub async fn channels( self, http: impl AsRef<Http>, ) -> Result<HashMap<ChannelId, GuildChannel>>
Gets all of the guild’s channels over the REST API.
§Errors
Returns Error::Http
if the current user is not in the guild.
Sourcepub async fn create_channel(
self,
cache_http: impl CacheHttp,
builder: CreateChannel<'_>,
) -> Result<GuildChannel>
pub async fn create_channel( self, cache_http: impl CacheHttp, builder: CreateChannel<'_>, ) -> Result<GuildChannel>
Creates a GuildChannel
in the the guild.
Refer to Http::create_channel
for more information.
Note: Requires the Manage Channels permission.
§Examples
Create a voice channel in a guild with the name test
:
use serenity::builder::CreateChannel;
use serenity::model::channel::ChannelType;
use serenity::model::id::GuildId;
let builder = CreateChannel::new("test").kind(ChannelType::Voice);
let _channel = GuildId::new(7).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>
pub async fn create_emoji( self, http: impl AsRef<Http>, name: &str, image: &str, ) -> Result<Emoji>
Creates an emoji in the guild with a name and base64-encoded image.
Refer to the documentation for Guild::create_emoji
for more information.
Requires the 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, if the name is too long, or
if the image is too big.
Sourcepub async fn create_integration(
self,
http: impl AsRef<Http>,
integration_id: impl Into<IntegrationId>,
kind: &str,
) -> Result<()>
pub async fn create_integration( self, http: impl AsRef<Http>, integration_id: impl Into<IntegrationId>, kind: &str, ) -> Result<()>
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_role(
self,
cache_http: impl CacheHttp,
builder: EditRole<'_>,
) -> Result<Role>
pub async fn create_role( self, cache_http: impl CacheHttp, builder: EditRole<'_>, ) -> Result<Role>
Creates a new role in the guild with the data set, if any.
See the documentation for Guild::create_role
on how to use this.
Note: Requires the Manage Roles permission.
§Errors
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>
pub async fn create_scheduled_event( self, cache_http: impl CacheHttp, builder: CreateScheduledEvent<'_>, ) -> Result<ScheduledEvent>
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>
pub async fn create_sticker( self, cache_http: impl CacheHttp, builder: CreateSticker<'_>, ) -> Result<Sticker>
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, http: impl AsRef<Http>) -> Result<()>
pub async fn delete(self, http: impl AsRef<Http>) -> Result<()>
Deletes the current guild if the current account is the owner of the guild.
Refer to Guild::delete
for more information.
Note: Requires the current user to be the owner of the guild.
§Errors
Returns Error::Http
if the current user is not the owner of the guild.
Sourcepub async fn delete_emoji(
self,
http: impl AsRef<Http>,
emoji_id: impl Into<EmojiId>,
) -> Result<()>
pub async fn delete_emoji( self, http: impl AsRef<Http>, emoji_id: impl Into<EmojiId>, ) -> Result<()>
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<()>
pub async fn delete_integration( self, http: impl AsRef<Http>, integration_id: impl Into<IntegrationId>, ) -> Result<()>
Deletes an integration by Id from the guild.
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http
if the current user lacks permission, or if an integration with
that Id does not exist.
Sourcepub async fn delete_role(
self,
http: impl AsRef<Http>,
role_id: impl Into<RoleId>,
) -> Result<()>
pub async fn delete_role( self, http: impl AsRef<Http>, role_id: impl Into<RoleId>, ) -> Result<()>
Deletes a Role
by Id from the guild.
Also see Role::delete
if you have the cache
and model
features enabled.
Note: Requires the Manage Roles permission.
§Errors
Returns Error::Http
if the current user lacks permission, or if a role with that Id
does not exist.
Sourcepub async fn delete_scheduled_event(
self,
http: impl AsRef<Http>,
event_id: impl Into<ScheduledEventId>,
) -> Result<()>
pub async fn delete_scheduled_event( self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, ) -> Result<()>
Deletes a specified scheduled event in 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, or if invalid data is given.
Sourcepub async fn delete_sticker(
self,
http: impl AsRef<Http>,
sticker_id: impl Into<StickerId>,
) -> Result<()>
pub async fn delete_sticker( self, http: impl AsRef<Http>, sticker_id: impl Into<StickerId>, ) -> Result<()>
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(
self,
cache_http: impl CacheHttp,
builder: EditGuild<'_>,
) -> Result<PartialGuild>
pub async fn edit( self, cache_http: impl CacheHttp, builder: EditGuild<'_>, ) -> Result<PartialGuild>
Edits the current guild with new data where specified.
Note: Requires the Manage Guild 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 edit_emoji(
self,
http: impl AsRef<Http>,
emoji_id: impl Into<EmojiId>,
name: &str,
) -> Result<Emoji>
pub async fn edit_emoji( self, http: impl AsRef<Http>, emoji_id: impl Into<EmojiId>, 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.
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>
pub async fn edit_member( self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, builder: EditMember<'_>, ) -> Result<Member>
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
Mute a member and set their roles to just one role with a predefined Id:
let builder = EditMember::new().mute(true).roles(vec![role_id]);
let _ = GuildId::new(7).edit_member(&http, user_id, builder).await?;
§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>
pub async fn edit_mfa_level( self, http: impl AsRef<Http>, mfa_level: MfaLevel, audit_log_reason: Option<&str>, ) -> Result<MfaLevel>
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,
http: impl AsRef<Http>,
new_nickname: Option<&str>,
) -> Result<()>
pub async fn edit_nickname( self, http: impl AsRef<Http>, new_nickname: Option<&str>, ) -> Result<()>
Edits the current user’s nickname for the guild.
Pass None
to reset the nickname.
Requires the Change Nickname permission.
§Errors
Returns 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>
pub async fn edit_role( self, cache_http: impl CacheHttp, role_id: impl Into<RoleId>, builder: EditRole<'_>, ) -> Result<Role>
Edits a Role
, optionally setting its new fields.
Note: Requires the Manage Roles permission.
§Examples
Make a role hoisted, and change its name:
// assuming a `role_id` and `guild_id` has been bound
let builder = EditRole::new().name("a test role").hoist(true);
let role = guild_id.edit_role(&http, role_id, 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_scheduled_event(
self,
cache_http: impl CacheHttp,
event_id: impl Into<ScheduledEventId>,
builder: EditScheduledEvent<'_>,
) -> Result<ScheduledEvent>
pub async fn edit_scheduled_event( self, cache_http: impl CacheHttp, event_id: impl Into<ScheduledEventId>, builder: EditScheduledEvent<'_>, ) -> Result<ScheduledEvent>
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>
pub async fn edit_sticker( self, cache_http: impl CacheHttp, sticker_id: impl Into<StickerId>, builder: EditSticker<'_>, ) -> Result<Sticker>
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::{GuildId, StickerId};
let builder = EditSticker::new().name("Bun bun meow");
let _ = GuildId::new(7).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_role_position(
self,
http: impl AsRef<Http>,
role_id: impl Into<RoleId>,
position: u16,
) -> Result<Vec<Role>>
pub async fn edit_role_position( self, http: impl AsRef<Http>, role_id: impl Into<RoleId>, position: u16, ) -> Result<Vec<Role>>
Edit the position of a Role
relative to all others in the Guild
.
Note: Requires the Manage Roles permission.
§Examples
use serenity::model::{GuildId, RoleId};
GuildId::new(7).edit_role_position(&context, RoleId::new(8), 2);
§Errors
Returns an Error::Http
if the current user lacks permission.
Sourcepub async fn edit_welcome_screen(
self,
cache_http: impl CacheHttp,
builder: EditGuildWelcomeScreen<'_>,
) -> Result<GuildWelcomeScreen>
pub async fn edit_welcome_screen( self, cache_http: impl CacheHttp, builder: EditGuildWelcomeScreen<'_>, ) -> Result<GuildWelcomeScreen>
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>
pub async fn edit_widget( self, cache_http: impl CacheHttp, builder: EditGuildWidget<'_>, ) -> Result<GuildWidget>
Edits the guild’s widget.
Note: Requires the Manage Guild permission.
§Errors
Returns Error::Http
if the current user lacks permission.
Sourcepub async fn role(self, http: impl AsRef<Http>, role_id: RoleId) -> Result<Role>
pub async fn role(self, http: impl AsRef<Http>, role_id: RoleId) -> Result<Role>
Gets a specific role in the guild, by Id.
§Errors
Returns Error::Http
if the current user is not in the guild, or if the role does not
exist.
Sourcepub async fn roles(
self,
http: impl AsRef<Http>,
) -> Result<HashMap<RoleId, Role>>
pub async fn roles( self, http: impl AsRef<Http>, ) -> Result<HashMap<RoleId, Role>>
Gets all of the guild’s roles over the REST API.
§Errors
Returns Error::Http
if the current user is not in
the guild.
Sourcepub fn everyone_role(&self) -> RoleId
pub fn everyone_role(&self) -> RoleId
Gets the default permission role (@everyone) from the guild.
Sourcepub fn to_guild_cached(self, cache: &impl AsRef<Cache>) -> Option<GuildRef<'_>>
pub fn to_guild_cached(self, cache: &impl AsRef<Cache>) -> Option<GuildRef<'_>>
Tries to find the Guild
by its Id in the cache.
Sourcepub async fn to_partial_guild(
self,
cache_http: impl CacheHttp,
) -> Result<PartialGuild>
pub async fn to_partial_guild( self, cache_http: impl CacheHttp, ) -> Result<PartialGuild>
Requests PartialGuild
over REST API.
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 async fn to_partial_guild_with_counts(
self,
http: impl AsRef<Http>,
) -> Result<PartialGuild>
pub async fn to_partial_guild_with_counts( self, http: impl AsRef<Http>, ) -> Result<PartialGuild>
Requests PartialGuild
over REST API with counts.
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 async fn emoji(
self,
http: impl AsRef<Http>,
emoji_id: EmojiId,
) -> Result<Emoji>
pub async fn emoji( self, http: impl AsRef<Http>, emoji_id: EmojiId, ) -> Result<Emoji>
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.
Sourcepub async fn stickers(self, http: impl AsRef<Http>) -> Result<Vec<Sticker>>
pub async fn stickers(self, http: impl AsRef<Http>) -> Result<Vec<Sticker>>
Gets all Sticker
s of this guild via HTTP.
§Errors
Returns an Error::Http
if the guild is unavailable.
Sourcepub async fn sticker(
self,
http: impl AsRef<Http>,
sticker_id: StickerId,
) -> Result<Sticker>
pub async fn sticker( self, http: impl AsRef<Http>, sticker_id: StickerId, ) -> Result<Sticker>
Gets an Sticker
of this guild by its ID via HTTP.
§Errors
Returns an Error::Http
if an sticker with that Id does not exist.
Sourcepub async fn integrations(
self,
http: impl AsRef<Http>,
) -> Result<Vec<Integration>>
pub async fn integrations( self, http: impl AsRef<Http>, ) -> Result<Vec<Integration>>
Gets all integration of the guild.
Requires the Manage Guild permission.
§Errors
Returns an Error::Http
if the current user lacks permission, also may return
Error::Json
if there is an error in deserializing the API response.
Sourcepub async fn invites(self, http: impl AsRef<Http>) -> Result<Vec<RichInvite>>
pub async fn invites(self, http: impl AsRef<Http>) -> Result<Vec<RichInvite>>
Gets all of the guild’s invites.
Requires the Manage Guild permission.
§Errors
Returns Error::Http
if the current user lacks permission, also may return
Error::Json
if there is an error in deserializing the API response.
Sourcepub async fn kick(
self,
http: impl AsRef<Http>,
user_id: impl Into<UserId>,
) -> Result<()>
pub async fn kick( self, http: impl AsRef<Http>, user_id: impl Into<UserId>, ) -> Result<()>
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<()>
pub async fn kick_with_reason( self, http: impl AsRef<Http>, user_id: impl Into<UserId>, reason: &str, ) -> Result<()>
§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>
pub async fn current_user_member(self, http: impl AsRef<Http>) -> Result<Member>
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<()>
pub async fn leave(self, http: impl AsRef<Http>) -> Result<()>
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<Member>
pub async fn member( self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, ) -> Result<Member>
Gets a user’s Member
for the guild by Id.
If the cache feature is enabled the cache will be checked first. If not found it will resort to an http request.
§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>>
pub async fn members( self, http: impl AsRef<Http>, limit: Option<u64>, after: impl Into<Option<UserId>>, ) -> Result<Vec<Member>>
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_iter<H: AsRef<Http>>(
self,
http: H,
) -> impl Stream<Item = Result<Member>>
pub fn members_iter<H: AsRef<Http>>( self, http: H, ) -> impl Stream<Item = Result<Member>>
Streams over all the members in a guild.
This is accomplished and equivalent to repeated calls to Self::members
. A buffer of at
most 1,000 members is used to reduce the number of calls necessary.
§Examples
use serenity::futures::StreamExt;
use serenity::model::guild::MembersIter;
let mut members = guild_id.members_iter(&ctx).boxed();
while let Some(member_result) = members.next().await {
match member_result {
Ok(member) => println!("{} is {}", member, member.display_name(),),
Err(error) => eprintln!("Uh oh! Error: {}", error),
}
}
Sourcepub async fn move_member(
self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
channel_id: impl Into<ChannelId>,
) -> Result<Member>
pub async fn move_member( self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, channel_id: impl Into<ChannelId>, ) -> Result<Member>
Moves a member to a specific voice channel.
Note: Requires the Move Members permission.
§Errors
Returns Error::Http
if the current user lacks permission, or if the member is not
currently in a voice channel for this Guild
.
Sourcepub fn name(self, cache: impl AsRef<Cache>) -> Option<String>
pub fn name(self, cache: impl AsRef<Cache>) -> Option<String>
Returns the name of whatever guild this id holds.
Sourcepub async fn disconnect_member(
self,
cache_http: impl CacheHttp,
user_id: impl Into<UserId>,
) -> Result<Member>
pub async fn disconnect_member( self, cache_http: impl CacheHttp, user_id: impl Into<UserId>, ) -> Result<Member>
Disconnects a member from a voice channel in the guild.
Note: Requires the Move Members permission.
§Errors
Returns Error::Http
if the current user lacks permission, or if the member is not
currently in a voice channel for this Guild
.
Sourcepub async fn prune_count(
self,
http: impl AsRef<Http>,
days: u8,
) -> Result<GuildPrune>
pub async fn prune_count( self, http: impl AsRef<Http>, days: u8, ) -> Result<GuildPrune>
Gets the number of Member
s that would be pruned with the given number of days.
Requires the Kick Members permission.
§Errors
Returns Error::Http
if the current user does not have permission.
Sourcepub async fn reorder_channels(
self,
http: impl AsRef<Http>,
channels: impl IntoIterator<Item = (ChannelId, u64)>,
) -> Result<()>
pub async fn reorder_channels( self, http: impl AsRef<Http>, channels: impl IntoIterator<Item = (ChannelId, u64)>, ) -> Result<()>
Re-orders the channels of the guild.
Accepts an iterator of a tuple of the channel ID to modify and its new position.
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 Error::Http
if the current user lacks permission.
Sourcepub async fn search_members(
self,
http: impl AsRef<Http>,
query: &str,
limit: Option<u64>,
) -> Result<Vec<Member>>
pub async fn search_members( self, http: impl AsRef<Http>, query: &str, limit: Option<u64>, ) -> Result<Vec<Member>>
Returns a list of Member
s 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.
§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>
pub async fn scheduled_event( self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, with_user_count: bool, ) -> Result<ScheduledEvent>
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>>
pub async fn scheduled_events( self, http: impl AsRef<Http>, with_user_count: bool, ) -> Result<Vec<ScheduledEvent>>
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>>
pub async fn scheduled_event_users( self, http: impl AsRef<Http>, event_id: impl Into<ScheduledEventId>, limit: Option<u64>, ) -> Result<Vec<ScheduledEventUser>>
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>>
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>>
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
pub fn shard_id(self, cache: impl AsRef<Cache>) -> u32
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 async fn start_integration_sync(
self,
http: impl AsRef<Http>,
integration_id: impl Into<IntegrationId>,
) -> Result<()>
pub async fn start_integration_sync( self, http: impl AsRef<Http>, integration_id: impl Into<IntegrationId>, ) -> Result<()>
Starts an integration sync for the given integration Id.
Requires the Manage Guild permission.
§Errors
Returns Error::Http
if the current user lacks permission, or if an Integration
with
that Id does not exist.
Sourcepub async fn start_prune(
self,
http: impl AsRef<Http>,
days: u8,
) -> Result<GuildPrune>
pub async fn start_prune( self, http: impl AsRef<Http>, days: u8, ) -> Result<GuildPrune>
Starts a prune of Member
s.
See the documentation on GuildPrune
for more information.
Note: Requires Kick Members and Manage Guild permissions.
§Errors
Returns Error::Http
if the current user lacks permission.
Sourcepub async fn unban(
self,
http: impl AsRef<Http>,
user_id: impl Into<UserId>,
) -> Result<()>
pub async fn unban( self, http: impl AsRef<Http>, user_id: impl Into<UserId>, ) -> Result<()>
Unbans a User
from the guild.
Note: Requires the Ban Members permission.
§Errors
Returns Error::Http
if the current user does not have permission.
Sourcepub async fn vanity_url(self, http: impl AsRef<Http>) -> Result<String>
pub async fn vanity_url(self, http: impl AsRef<Http>) -> Result<String>
Retrieve’s the guild’s vanity URL.
Note: Requires the Manage Guild permission.
§Errors
Will return Error::Http
if the current user lacks permission. Can also return
Error::Json
if there is an error deserializing the API response.
Sourcepub async fn webhooks(self, http: impl AsRef<Http>) -> Result<Vec<Webhook>>
pub async fn webhooks(self, http: impl AsRef<Http>) -> Result<Vec<Webhook>>
Retrieves the guild’s webhooks.
Note: Requires the Manage Webhooks permission.
§Errors
Will return an Error::Http
if the bot is lacking permissions. Can also return an
Error::Json
if there is an error deserializing the API response.
Sourcepub fn await_reply(
self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
pub fn await_reply( self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
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
pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
Same as Self::await_reply
.
Sourcepub fn await_reaction(
self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reaction( self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
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
pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Same as Self::await_reaction
.
Sourcepub async fn create_command(
self,
cache_http: impl CacheHttp,
builder: CreateCommand,
) -> Result<Command>
pub async fn create_command( self, cache_http: impl CacheHttp, builder: CreateCommand, ) -> Result<Command>
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>>
pub async fn set_commands( self, http: impl AsRef<Http>, commands: Vec<CreateCommand>, ) -> Result<Vec<Command>>
Sourcepub async fn edit_command_permissions(
self,
cache_http: impl CacheHttp,
command_id: CommandId,
builder: EditCommandPermissions,
) -> Result<CommandPermissions>
pub async fn edit_command_permissions( self, cache_http: impl CacheHttp, command_id: CommandId, builder: EditCommandPermissions, ) -> Result<CommandPermissions>
Overwrites permissions for a specific command.
Note: It will update instantly.
§Errors
See EditCommandPermissions::execute
for a list of possible errors.
Sourcepub async fn get_commands(self, http: impl AsRef<Http>) -> Result<Vec<Command>>
pub async fn get_commands(self, http: impl AsRef<Http>) -> Result<Vec<Command>>
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>>
pub async fn get_commands_with_localizations( self, http: impl AsRef<Http>, ) -> Result<Vec<Command>>
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>
pub async fn get_command( self, http: impl AsRef<Http>, command_id: CommandId, ) -> Result<Command>
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>
pub async fn edit_command( self, cache_http: impl CacheHttp, command_id: CommandId, builder: CreateCommand, ) -> Result<Command>
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<()>
pub async fn delete_command( self, http: impl AsRef<Http>, command_id: CommandId, ) -> Result<()>
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>>
pub async fn get_commands_permissions( self, http: impl AsRef<Http>, ) -> Result<Vec<CommandPermissions>>
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>
pub async fn get_command_permissions( self, http: impl AsRef<Http>, command_id: CommandId, ) -> Result<CommandPermissions>
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 get_welcome_screen(
self,
http: impl AsRef<Http>,
) -> Result<GuildWelcomeScreen>
pub async fn get_welcome_screen( self, http: impl AsRef<Http>, ) -> Result<GuildWelcomeScreen>
Get the guild welcome screen.
§Errors
Returns Error::Http
if the guild does not have a welcome screen.
Sourcepub async fn get_preview(self, http: impl AsRef<Http>) -> Result<GuildPreview>
pub async fn get_preview(self, http: impl AsRef<Http>) -> Result<GuildPreview>
Get the guild preview.
Note: The bot need either to be part of the guild or the guild needs to have the
DISCOVERABLE
feature.
§Errors
Returns Error::Http
if the bot cannot see the guild preview, see the note.
Sourcepub async fn get_widget(self, http: impl AsRef<Http>) -> Result<GuildWidget>
pub async fn get_widget(self, http: impl AsRef<Http>) -> Result<GuildWidget>
Get the guild widget.
§Errors
Returns Error::Http
if the bot does not have MANAGE_MESSAGES
permission.
Sourcepub fn widget_image_url(self, style: GuildWidgetStyle) -> String
pub fn widget_image_url(self, style: GuildWidgetStyle) -> String
Get the widget image URL.
Sourcepub async fn get_active_threads(
self,
http: impl AsRef<Http>,
) -> Result<ThreadsData>
pub async fn get_active_threads( self, http: impl AsRef<Http>, ) -> Result<ThreadsData>
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§
Source§impl<'de> Deserialize<'de> for GuildId
impl<'de> Deserialize<'de> for GuildId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&InviteGuild> for GuildId
impl From<&InviteGuild> for GuildId
Source§fn from(invite_guild: &InviteGuild) -> GuildId
fn from(invite_guild: &InviteGuild) -> GuildId
Gets the Id of Invite Guild struct.
Source§impl From<&PartialGuild> for GuildId
impl From<&PartialGuild> for GuildId
Source§fn from(guild: &PartialGuild) -> GuildId
fn from(guild: &PartialGuild) -> GuildId
Gets the Id of a partial guild.
Source§impl From<&WebhookGuild> for GuildId
impl From<&WebhookGuild> for GuildId
Source§fn from(webhook_guild: &WebhookGuild) -> GuildId
fn from(webhook_guild: &WebhookGuild) -> GuildId
Gets the Id of Webhook Guild struct.
Source§impl From<GuildId> for NonZeroI64
impl From<GuildId> for NonZeroI64
Source§fn from(id: GuildId) -> NonZeroI64
fn from(id: GuildId) -> NonZeroI64
Source§impl From<GuildId> for NonZeroU64
impl From<GuildId> for NonZeroU64
Source§fn from(id: GuildId) -> NonZeroU64
fn from(id: GuildId) -> NonZeroU64
Source§impl From<InviteGuild> for GuildId
impl From<InviteGuild> for GuildId
Source§fn from(invite_guild: InviteGuild) -> GuildId
fn from(invite_guild: InviteGuild) -> GuildId
Gets the Id of Invite Guild struct.
Source§impl From<NonZero<u64>> for GuildId
impl From<NonZero<u64>> for GuildId
Source§fn from(id: NonZeroU64) -> GuildId
fn from(id: NonZeroU64) -> GuildId
Source§impl From<PartialGuild> for GuildId
impl From<PartialGuild> for GuildId
Source§fn from(guild: PartialGuild) -> GuildId
fn from(guild: PartialGuild) -> GuildId
Gets the Id of a partial guild.
Source§impl From<WebhookGuild> for GuildId
impl From<WebhookGuild> for GuildId
Source§fn from(webhook_guild: WebhookGuild) -> GuildId
fn from(webhook_guild: WebhookGuild) -> GuildId
Gets the Id of Webhook Guild struct.
Source§impl Ord for GuildId
impl Ord for GuildId
Source§impl PartialOrd for GuildId
impl PartialOrd for GuildId
impl Copy for GuildId
impl Eq for GuildId
impl StructuralPartialEq for GuildId
Auto Trait Implementations§
impl Freeze for GuildId
impl RefUnwindSafe for GuildId
impl Send for GuildId
impl Sync for GuildId
impl Unpin for GuildId
impl UnwindSafe for GuildId
Blanket Implementations§
Source§impl<T> ArgumentConvert for Twhere
T: FromStr,
impl<T> ArgumentConvert for Twhere
T: FromStr,
Source§fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
fn convert<'life0, 'async_trait>(
__arg0: impl CacheHttp + 'async_trait,
__arg1: Option<GuildId>,
__arg2: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<T, <T as ArgumentConvert>::Err>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: 'async_trait,
s
as a command parameter of this type.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.