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

pub struct ChannelId(pub u64);
Expand description

An identifier for a Channel

Implementations

Broadcasts that the current user is typing to a channel for the next 5 seconds.

After 5 seconds, another request must be made to continue broadcasting that the current user is typing.

This should rarely be used for bots, and should likely only be used for signifying that a long-running command is still being executed.

Note: Requires the Send Messages permission.

Examples

use serenity::model::id::ChannelId;

let _successful = ChannelId(7).broadcast_typing(&http).await;

Errors

Returns Error::Http if the current user lacks permission to send messages to this channel.

Creates an invite leading to the given channel.

Note: Requres the Create Invite permission.

Errors

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

Creates a permission overwrite for either a single Member or Role within the channel.

Refer to the documentation for GuildChannel::create_permission for more information.

Requires the Manage Channels permission.

Errors

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

React to a Message with a custom Emoji or unicode character.

Message::react may be a more suited method of reacting in most cases.

Requires the Add Reactions permission, if the current user is the first user to perform a react with a certain emoji.

Errors

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

Deletes this channel, returning the channel on a successful deletion.

Note: Requires the Manage Channels permission.

Errors

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

Deletes a Message given its Id.

Refer to Message::delete for more information.

Requires the Manage Messages permission, if the current user is not the author of the message.

Errors

Returns Error::Http if the current user lacks permission to delete the message.

Deletes all messages by Ids from the given vector in the given channel.

The minimum amount of messages is 2 and the maximum amount is 100.

Requires the Manage Messages permission.

Note: Messages that are older than 2 weeks can’t be deleted using this method.

Errors

Returns ModelError::BulkDeleteAmount if an attempt was made to delete either 0 or more than 100 messages.

Also will return Error::Http if the current user lacks permission to delete messages.

Deletes all permission overrides in the channel from a member or role.

Note: Requires the Manage Channel permission.

Errors

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

Deletes the given Reaction from the channel.

Note: Requires the Manage Messages permission, if the current user did not perform the reaction.

Errors

Returns Error::Http if the current user did not perform the reaction, and lacks permission.

Deletes all Reactions of the given emoji to a message within the channel.

Note: Requires the Manage Messages permission.

Errors

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

Edits the settings of a Channel, optionally setting new values.

Refer to EditChannel’s documentation for its methods.

Requires the Manage Channel permission.

Examples

Change a voice channel’s name and bitrate:

// assuming a `channel_id` has been bound

channel_id.edit(&http, |c| c.name("test").bitrate(64000)).await;

Errors

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

Edits a Message in the channel given its Id.

Message editing preserves all unchanged message data.

Refer to the documentation for EditMessage for more information regarding message restrictions and requirements.

Note: Requires that the current user be the author of the message.

Errors

Returns a ModelError::MessageTooLong if the content of the message is over the the limit, containing the number of unicode code points over the limit.

Attempts to find a Channel by its Id in the cache.

First attempts to find a Channel by its Id in the cache, upon failure requests it via the REST API.

Note: If the cache-feature is enabled permissions will be checked and upon owning the required permissions the HTTP-request will be issued.

Gets all of the channel’s invites.

Requires the Manage Channels permission.

Errors

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

Gets a message from the channel.

Requires the Read Message History permission.

Errors

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

Gets messages from the channel.

Refer to GetMessages for more information on how to use builder.

Note: Returns an empty Vec if the current user does not have the Read Message History permission.

Errors

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

Streams over all the messages in a channel.

This is accomplished and equivalent to repeated calls to Self::messages. A buffer of at most 100 messages is used to reduce the number of calls. necessary.

The stream returns the newest message first, followed by older messages.

Examples

use serenity::model::channel::MessagesIter;
use serenity::futures::StreamExt;

let mut messages = channel_id.messages_iter(&ctx).boxed();
while let Some(message_result) = messages.next().await {
    match message_result {
        Ok(message) => println!(
            "{} said \"{}\".",
            message.author.name,
            message.content,
        ),
        Err(error) => eprintln!("Uh oh! Error: {}", error),
    }
}

Returns the name of whatever channel this id holds.

Pins a Message to the channel.

Note: Requires the Manage Messages permission.

Errors

Returns Error::Http if the current user lacks permission, or if the channel has too many pinned messages.

Crossposts a Message.

Requires either to be the message author or to have manage Manage Messages permissions on this channel.

Note: Only available on announcements channels.

Errors

Gets the list of Messages which are pinned to the channel.

Note: Returns an empty Vec if the current user does not have the Read Message History permission.

Errors

Returns Error::Http if the current user lacks permission to view the channel.

Gets the list of Users who have reacted to a Message with a certain Emoji.

The default limit is 50 - specify otherwise to receive a different maximum number of users. The maximum that may be retrieve at a time is 100, if a greater number is provided then it is automatically reduced.

The optional after attribute is to retrieve the users after a certain user. This is useful for pagination.

Note: Requires the Read Message History permission.

Errors

Returns Error::Http if the current user lacks permission to read messages in the channel.

Sends a message with just the given message content in the channel.

Errors

Returns a ModelError::MessageTooLong if the content of the message is over the above limit, containing the number of unicode code points over the limit.

Sends file(s) along with optional message contents. The filename must be specified.

Message contents may be passed by using the CreateMessage::content method.

The Attach Files and Send Messages permissions are required.

Note: Message contents must be under 2000 unicode code points.

Examples

Send files with the paths /path/to/file.jpg and /path/to/file2.jpg:

use serenity::model::id::ChannelId;

let channel_id = ChannelId(7);

let paths = vec!["/path/to/file.jpg", "path/to/file2.jpg"];

let _ = channel_id.send_files(&http, paths, |m| {
    m.content("a file")
})
.await;

Send files using File:

use serenity::model::id::ChannelId;
use tokio::fs::File;

let channel_id = ChannelId(7);

let f1 = File::open("my_file.jpg").await?;
let f2 = File::open("my_file2.jpg").await?;

let files = vec![(&f1, "my_file.jpg"), (&f2, "my_file2.jpg")];

let _ = channel_id.send_files(&http, files, |m| {
    m.content("a file")
})
.await;

Errors

If the content of the message is over the above limit, then a ModelError::MessageTooLong will be returned, containing the number of unicode code points over the limit.

Returns an HttpError::UnsuccessfulRequest(ErrorResponse) if the file(s) are too large to send.

Sends a message to the channel.

Refer to the documentation for CreateMessage for more information regarding message restrictions and requirements.

Requires the Send Messages permission.

Note: Message contents must be under 2000 unicode code points.

Errors

Returns a ModelError::MessageTooLong if the content of the message is over the above limit, containing the number of unicode code points over the limit.

Returns Error::Http if the current user lacks permission to send a message in this channel.

Starts typing in the channel for an indefinite period of time.

Returns Typing that is used to trigger the typing. Typing::stop must be called on the returned struct to stop typing. Note that on some clients, typing may persist for a few seconds after Typing::stop is called. Typing is also stopped when the struct is dropped.

If a message is sent while typing is triggered, the user will stop typing for a brief period of time and then resume again until either Typing::stop is called or the struct is dropped.

This should rarely be used for bots, although it is a good indicator that a long-running command is still being processed.

Examples

// Initiate typing (assuming http is `Arc<Http>`)
let typing = ChannelId(7).start_typing(&http)?;

// Run some long-running process
long_process();

// Stop typing
typing.stop();

Errors

Returns Error::Http if the current user lacks permission to send messages in this channel.

Unpins a Message in the channel given by its Id.

Requires the Manage Messages permission.

Errors

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

Retrieves the channel’s webhooks.

Note: Requires the Manage Webhooks permission.

Errors

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

Creates a webhook with only a name.

Errors

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

Creates a webhook with a name and an avatar.

Errors

In addition to the reasons Self::create_webhook may return an Error::Http, if the image is too large.

This is supported on crate feature collector only.

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

This is supported on crate feature collector only.

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

This is supported on crate feature collector only.

Await a single reaction in this guild.

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

Retrieves the time that the Id was created at.

Immutably borrow inner Id.

Mutably borrow inner Id.

Trait Implementations

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Gets the Id of a Channel.

Performs the conversion.

Gets the Id of a guild channel.

Gets the Id of a private channel.

Gets the Id of a Channel.

Performs the conversion.

Gets the Id of a guild channel.

Gets the Id of a private channel.

Performs the conversion.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Creates a Mention that will be able to notify or create a link to the item. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.