Struct serenity::model::id::GuildId[][src]

pub struct GuildId(pub u64);

An identifier for a Guild

Implementations

impl GuildId[src]

pub async fn ban(
    self,
    http: impl AsRef<Http>,
    user: impl Into<UserId>,
    dmd: u8
) -> Result<()>
[src]

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::UserId;
use serenity::model::id::GuildId;

// assuming a `user` has already been bound
let _ = GuildId(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.

pub async fn ban_with_reason(
    self,
    http: impl AsRef<Http>,
    user: impl Into<UserId>,
    dmd: u8,
    reason: impl AsRef<str>
) -> Result<()>
[src]

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

Errors

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

pub async fn bans(self, http: impl AsRef<Http>) -> Result<Vec<Ban>>[src]

Gets a list of the guild’s bans.

Note: Requires the Ban Members permission.

Errors

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

pub async fn audit_logs(
    self,
    http: impl AsRef<Http>,
    action_type: Option<u8>,
    user_id: Option<UserId>,
    before: Option<AuditLogEntryId>,
    limit: Option<u8>
) -> Result<AuditLogs>
[src]

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.

pub async fn channels(
    self,
    http: impl AsRef<Http>
) -> Result<HashMap<ChannelId, GuildChannel>>
[src]

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

Errors

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

pub async fn create_channel(
    self,
    http: impl AsRef<Http>,
    f: impl FnOnce(&mut CreateChannel) -> &mut CreateChannel
) -> Result<GuildChannel>
[src]

Creates a GuildChannel in the the guild.

Refer to Http::create_channel for more information.

Requires the Manage Channels permission.

Examples

Create a voice channel in a guild with the name test:

use serenity::model::id::GuildId;
use serenity::model::channel::ChannelType;

let _channel = GuildId(7).create_channel(&http, |c| c.name("test").kind(ChannelType::Voice)).await;

Errors

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

pub async fn create_emoji(
    self,
    http: impl AsRef<Http>,
    name: &str,
    image: &str
) -> Result<Emoji>
[src]

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 Manage Emojis permission.

Examples

See the EditProfile::avatar example for an in-depth example as to how to read an image from the filesystem and encode it as base64. Most of the example can be applied similarly for this method.

Errors

Returns Error::Http if the current user lacks permission, if the name is too long, or if the image is too big.

pub async fn create_integration(
    self,
    http: impl AsRef<Http>,
    integration_id: impl Into<IntegrationId>,
    kind: &str
) -> Result<()>
[src]

Creates an integration for the guild.

Requires the Manage Guild permission.

Errors

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

pub async fn create_application_command<F>(
    self,
    http: impl AsRef<Http>,
    application_id: u64,
    f: F
) -> Result<ApplicationCommand> where
    F: FnOnce(&mut CreateInteraction) -> &mut CreateInteraction
[src]

This is supported on crate feature unstable_discord_api only.

Creates a new ApplicationCommand for the guild.

See the documentation for Interaction::create_global_application_command on how to use this.

Note: application_id is usually the bot’s id, unless it’s a very old bot.

Errors

Returns Error::Http if invalid data is given, may also return Error::Json if there is an error in deserializing the API response.

pub async fn create_role<F>(self, http: impl AsRef<Http>, f: F) -> Result<Role> where
    F: FnOnce(&mut EditRole) -> &mut EditRole
[src]

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

Returns Error::Http if the current user lacks permission, or if invalid data is given.

pub async fn delete(self, http: impl AsRef<Http>) -> Result<PartialGuild>[src]

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.

pub async fn delete_emoji(
    self,
    http: impl AsRef<Http>,
    emoji_id: impl Into<EmojiId>
) -> Result<()>
[src]

Deletes an Emoji from the guild.

Note: Requires the Manage Emojis permission.

Errors

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

pub async fn delete_integration(
    self,
    http: impl AsRef<Http>,
    integration_id: impl Into<IntegrationId>
) -> Result<()>
[src]

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.

pub async fn delete_role(
    self,
    http: impl AsRef<Http>,
    role_id: impl Into<RoleId>
) -> Result<()>
[src]

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.

pub async fn edit<F>(
    &mut self,
    http: impl AsRef<Http>,
    f: F
) -> Result<PartialGuild> where
    F: FnOnce(&mut EditGuild) -> &mut EditGuild
[src]

Edits the current guild with new data where specified.

Refer to Guild::edit for more information.

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

Errors

Returns Error::Http if the current user lacks permission, or if an invalid value is set.

pub async fn edit_emoji(
    self,
    http: impl AsRef<Http>,
    emoji_id: impl Into<EmojiId>,
    name: &str
) -> Result<Emoji>
[src]

Edits an Emoji’s name in the guild.

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

Requires the Manage Emojis permission.

Errors

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

pub async fn edit_member<F>(
    self,
    http: impl AsRef<Http>,
    user_id: impl Into<UserId>,
    f: F
) -> Result<Member> where
    F: FnOnce(&mut EditMember) -> &mut EditMember
[src]

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

Refer to EditMember’s documentation for a full list of methods and permission restrictions.

Examples

Mute a member and set their roles to just one role with a predefined Id:

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

Errors

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

pub async fn edit_nickname(
    self,
    http: impl AsRef<Http>,
    new_nickname: Option<&str>
) -> Result<()>
[src]

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.

pub async fn edit_role<F>(
    self,
    http: impl AsRef<Http>,
    role_id: impl Into<RoleId>,
    f: F
) -> Result<Role> where
    F: FnOnce(&mut EditRole) -> &mut EditRole
[src]

Edits a Role, optionally setting its new fields.

Requires the Manage Roles permission.

Examples

Make a role hoisted:

use serenity::model::{GuildId, RoleId};

GuildId(7).edit_role(&context, RoleId(8), |r| r.hoist(true));

Errors

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

pub async fn edit_role_position(
    self,
    http: impl AsRef<Http>,
    role_id: impl Into<RoleId>,
    position: u64
) -> Result<Vec<Role>>
[src]

Edits the order of Roles Requires the Manage Roles permission.

Examples

Change the order of a role:

use serenity::model::{GuildId, RoleId};
GuildId(7).edit_role_position(&context, RoleId(8), 2);

Errors

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

pub async fn to_guild_cached(self, cache: impl AsRef<Cache>) -> Option<Guild>[src]

Tries to find the Guild by its Id in the cache.

pub async fn to_partial_guild(
    self,
    http: impl AsRef<Http>
) -> Result<PartialGuild>
[src]

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.

pub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>>[src]

Gets all Emojis of this guild via HTTP.

Errors

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

pub async fn emoji(
    &self,
    http: impl AsRef<Http>,
    emoji_id: EmojiId
) -> Result<Emoji>
[src]

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.

pub async fn integrations(
    self,
    http: impl AsRef<Http>
) -> Result<Vec<Integration>>
[src]

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.

pub async fn invites(self, http: impl AsRef<Http>) -> Result<Vec<RichInvite>>[src]

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.

pub async fn kick(
    self,
    http: impl AsRef<Http>,
    user_id: impl Into<UserId>
) -> Result<()>
[src]

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.

pub async fn kick_with_reason(
    self,
    http: impl AsRef<Http>,
    user_id: impl Into<UserId>,
    reason: &str
) -> Result<()>
[src]

Errors

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

pub async fn leave(self, http: impl AsRef<Http>) -> Result<()>[src]

Leaves the guild.

Errors

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

pub async fn member(
    self,
    cache_http: impl CacheHttp,
    user_id: impl Into<UserId>
) -> Result<Member>
[src]

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

pub async fn members(
    self,
    http: impl AsRef<Http>,
    limit: Option<u64>,
    after: impl Into<Option<UserId>>
) -> Result<Vec<Member>>
[src]

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.

pub fn members_iter<H: AsRef<Http>>(
    self,
    http: H
) -> impl Stream<Item = Result<Member>>
[src]

Streams over all the members in a guild.

This is accomplished and equivalent to repeated calls to members. A buffer of at most 1,000 members is used to reduce the number of calls necessary.

Examples

use serenity::model::guild::MembersIter;
use serenity::futures::StreamExt;

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),
    }
}

pub async fn move_member(
    self,
    http: impl AsRef<Http>,
    user_id: impl Into<UserId>,
    channel_id: impl Into<ChannelId>
) -> Result<Member>
[src]

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.

pub async fn name(self, cache: impl AsRef<Cache>) -> Option<String>[src]

Returns the name of whatever guild this id holds.

pub async fn disconnect_member(
    self,
    http: impl AsRef<Http>,
    user_id: impl Into<UserId>
) -> Result<Member>
[src]

Disconnects a member from a voice channel in the guild.

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.

pub async fn prune_count(
    self,
    http: impl AsRef<Http>,
    days: u16
) -> Result<GuildPrune>
[src]

Gets the number of Members 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.

pub async fn reorder_channels<It>(
    self,
    http: impl AsRef<Http>,
    channels: It
) -> Result<()> where
    It: IntoIterator<Item = (ChannelId, u64)>, 
[src]

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.

pub async fn shard_id(self, cache: impl AsRef<Cache>) -> u64[src]

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.

pub async fn start_integration_sync(
    self,
    http: impl AsRef<Http>,
    integration_id: impl Into<IntegrationId>
) -> Result<()>
[src]

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.

pub async fn start_prune(
    self,
    http: impl AsRef<Http>,
    days: u16
) -> Result<GuildPrune>
[src]

Starts a prune of Members.

See the documentation on GuildPrune for more information.

Note: Requires the Kick Members permission.

Errors

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

pub async fn unban(
    self,
    http: impl AsRef<Http>,
    user_id: impl Into<UserId>
) -> Result<()>
[src]

Unbans a User from the guild.

Note: Requires the Ban Members permission.

Errors

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

pub async fn vanity_url(self, http: impl AsRef<Http>) -> Result<String>[src]

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.

pub async fn webhooks(self, http: impl AsRef<Http>) -> Result<Vec<Webhook>>[src]

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.

pub fn await_reply<'a>(
    &self,
    shard_messenger: &'a impl AsRef<ShardMessenger>
) -> CollectReply<'a>

Notable traits for CollectReply<'a>

impl<'a> Future for CollectReply<'a> type Output = Option<Arc<Message>>;
[src]

This is supported on crate feature collector only.

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

pub fn await_replies<'a>(
    &self,
    shard_messenger: &'a impl AsRef<ShardMessenger>
) -> MessageCollectorBuilder<'a>

Notable traits for MessageCollectorBuilder<'a>

impl<'a> Future for MessageCollectorBuilder<'a> type Output = MessageCollector;
[src]

This is supported on crate feature collector only.

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

pub fn await_reaction<'a>(
    &self,
    shard_messenger: &'a impl AsRef<ShardMessenger>
) -> CollectReaction<'a>

Notable traits for CollectReaction<'a>

impl<'a> Future for CollectReaction<'a> type Output = Option<Arc<ReactionAction>>;
[src]

This is supported on crate feature collector only.

Await a single reaction in this guild.

pub fn await_reactions<'a>(
    &self,
    shard_messenger: &'a impl AsRef<ShardMessenger>
) -> ReactionCollectorBuilder<'a>
[src]

This is supported on crate feature collector only.

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

impl GuildId[src]

pub fn created_at(&self) -> DateTime<Utc>[src]

Retrieves the time that the Id was created at.

pub fn as_u64(&self) -> &u64[src]

Immutably borrow inner Id.

pub fn as_mut_u64(&mut self) -> &mut u64[src]

Mutably borrow inner Id.

Trait Implementations

impl AsRef<GuildId> for GuildId[src]

impl Clone for GuildId[src]

impl Copy for GuildId[src]

impl Debug for GuildId[src]

impl Default for GuildId[src]

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

impl Display for GuildId[src]

impl Eq for GuildId[src]

impl<'a> From<&'a Guild> for GuildId[src]

fn from(live_guild: &Guild) -> GuildId[src]

Gets the Id of Guild.

impl<'a> From<&'a GuildId> for GuildId[src]

impl<'a> From<&'a GuildInfo> for GuildId[src]

fn from(guild_info: &GuildInfo) -> GuildId[src]

Gets the Id of Guild information struct.

impl<'a> From<&'a InviteGuild> for GuildId[src]

fn from(invite_guild: &InviteGuild) -> GuildId[src]

Gets the Id of Invite Guild struct.

impl<'a> From<&'a PartialGuild> for GuildId[src]

fn from(guild: &PartialGuild) -> GuildId[src]

Gets the Id of a partial guild.

impl From<Guild> for GuildId[src]

fn from(live_guild: Guild) -> GuildId[src]

Gets the Id of Guild.

impl From<GuildId> for GuildContainer[src]

impl From<GuildInfo> for GuildId[src]

fn from(guild_info: GuildInfo) -> GuildId[src]

Gets the Id of Guild information struct.

impl From<InviteGuild> for GuildId[src]

fn from(invite_guild: InviteGuild) -> GuildId[src]

Gets the Id of Invite Guild struct.

impl From<PartialGuild> for GuildId[src]

fn from(guild: PartialGuild) -> GuildId[src]

Gets the Id of a partial guild.

impl From<u64> for GuildId[src]

impl Hash for GuildId[src]

impl Ord for GuildId[src]

impl PartialEq<GuildId> for GuildId[src]

impl PartialEq<u64> for GuildId[src]

impl PartialOrd<GuildId> for GuildId[src]

impl Serialize for GuildId[src]

impl StructuralEq for GuildId[src]

impl StructuralPartialEq for GuildId[src]

Auto Trait Implementations

impl RefUnwindSafe for GuildId

impl Send for GuildId

impl Sync for GuildId

impl Unpin for GuildId

impl UnwindSafe for GuildId

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,