Struct serenity::model::channel::GuildChannel[][src]

pub struct GuildChannel {
    pub id: ChannelId,
    pub bitrate: Option<u64>,
    pub category_id: Option<ChannelId>,
    pub guild_id: GuildId,
    pub kind: ChannelType,
    pub last_message_id: Option<MessageId>,
    pub last_pin_timestamp: Option<DateTime<FixedOffset>>,
    pub name: String,
    pub permission_overwrites: Vec<PermissionOverwrite>,
    pub position: i64,
    pub topic: Option<String>,
    pub user_limit: Option<u64>,
    pub nsfw: bool,
}

Represents a guild's text or voice channel. Some methods are available only for voice channels and some are only available for text channels.

Fields

The unique Id of the channel.

The default channel Id shares the Id of the guild and the default role.

The bitrate of the channel.

Note: This is only available for voice channels.

Whether this guild channel belongs in a category.

The Id of the guild the channel is located in.

If this matches with the id, then this is the default text channel.

The original voice channel has an Id equal to the guild's Id, incremented by one.

The type of the channel.

The Id of the last message sent in the channel.

Note: This is only available for text channels.

The timestamp of the time a pin was most recently made.

Note: This is only available for text channels.

The name of the channel.

Permission overwrites for Members and for Roles.

The position of the channel.

The default text channel will almost always have a position of -1 or 0.

The topic of the channel.

Note: This is only available for text channels.

The maximum number of members allowed in the channel.

Note: This is only available for voice channels.

Used to tell if the channel is not safe for work. Note however, it's recommended to use is_nsfw as it's gonna be more accurate.

Methods

impl GuildChannel
[src]

Broadcasts to the channel that the current user is typing.

For bots, this is a good indicator for long-running commands.

Note: Requires the Send Messages permission.

Errors

Returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Creates an invite leading to the given channel.

Examples

Create an invite that can only be used 5 times:

This example is not tested
let invite = channel.create_invite(|i| i.max_uses(5));

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

Refer to the documentation for PermissionOverwrites for more information.

Requires the Manage Channels permission.

Examples

Creating a permission overwrite for a member by specifying the PermissionOverwrite::Member variant, allowing it the Send Messages permission, but denying the Send TTS Messages and Attach Files permissions:

use serenity::model::channel::{
    PermissionOverwrite,
    PermissionOverwriteType,
};
use serenity::model::{ModelError, Permissions};
use serenity::CACHE;

let allow = Permissions::SEND_MESSAGES;
let deny = Permissions::SEND_TTS_MESSAGES | Permissions::ATTACH_FILES;
let overwrite = PermissionOverwrite {
    allow: allow,
    deny: deny,
    kind: PermissionOverwriteType::Member(user_id),
};

let cache = CACHE.read();
let channel = cache
    .guild_channel(channel_id)
    .ok_or(ModelError::ItemMissing)?;

channel.read().create_permission(&overwrite)?;

Creating a permission overwrite for a role by specifying the PermissionOverwrite::Role variant, allowing it the Manage Webhooks permission, but denying the Send TTS Messages and Attach Files permissions:

use serenity::model::channel::{
    PermissionOverwrite,
    PermissionOverwriteType,
};
use serenity::model::{ModelError, Permissions};
use serenity::CACHE;

let allow = Permissions::SEND_MESSAGES;
let deny = Permissions::SEND_TTS_MESSAGES | Permissions::ATTACH_FILES;
let overwrite = PermissionOverwrite {
    allow: allow,
    deny: deny,
    kind: PermissionOverwriteType::Member(user_id),
};

let cache = CACHE.read();
let channel = cache
    .guild_channel(channel_id)
    .ok_or(ModelError::ItemMissing)?;

channel.read().create_permission(&overwrite)?;

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

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

Refer to Channel::delete_messages for more information.

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.

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

Note: Requires the Manage Channel permission.

Deletes the given Reaction from the channel.

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

Modifies a channel's settings, such as its position or name.

Refer to EditChannels documentation for a full list of methods.

Examples

Change a voice channels name and bitrate:

This example is not tested
channel.edit(|c| c.name("test").bitrate(86400));

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 this channel's guild in the Cache.

Note: Right now this performs a clone of the guild. This will be optimized in the future.

Gets all of the channel's invites.

Requires the [Manage Channels] permission. [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html

Determines if the channel is NSFW.

Refer to utils::is_nsfw for more details.

Only text channels are taken into consideration as being NSFW. voice channels are never NSFW.

Gets a message from the channel.

Requires the Read Message History permission.

Gets messages from the channel.

Refer to Channel::messages for more information.

Requires the Read Message History permission.

Returns the name of the guild channel.

Calculates the permissions of a member.

The Id of the argument must be a Member of the Guild that the channel is in.

Examples

Calculate the permissions of a User who posted a Message in a channel:

use serenity::prelude::*;
use serenity::model::prelude::*;
struct Handler;

use serenity::CACHE;

impl EventHandler for Handler {
    fn message(&self, _: Context, msg: Message) {
        let channel = match CACHE.read().guild_channel(msg.channel_id) {
            Some(channel) => channel,
            None => return,
        };

        let permissions = channel.read().permissions_for(&msg.author).unwrap();

        println!("The user's permissions: {:?}", permissions);
    }
}
let mut client = Client::new("token", Handler).unwrap();

client.start().unwrap();

Check if the current user has the Attach Files and Send Messages permissions (note: serenity will automatically check this for; this is for demonstrative purposes):

use serenity::CACHE;
use serenity::prelude::*;
use serenity::model::prelude::*;
use std::fs::File;

struct Handler;

impl EventHandler for Handler {
    fn message(&self, _: Context, msg: Message) {
        let channel = match CACHE.read().guild_channel(msg.channel_id) {
            Some(channel) => channel,
            None => return,
        };

        let current_user_id = CACHE.read().user.id;
        let permissions =
            channel.read().permissions_for(current_user_id).unwrap();

        if !permissions.contains(Permissions::ATTACH_FILES | Permissions::SEND_MESSAGES) {
            return;
        }

        let file = match File::open("./cat.png") {
            Ok(file) => file,
            Err(why) => {
                println!("Err opening file: {:?}", why);

                return;
            },
        };

        let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |m|
            m.content("here's a cat"));
    }
}

let mut client = Client::new("token", Handler).unwrap();

client.start().unwrap();

Errors

Returns a ModelError::GuildNotFound if the channel's guild could not be found in the Cache.

Pins a Message to the channel.

Gets all channel's pins.

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

Refer to Channel::reaction_users for more information.

Note: Requires the Read Message History permission.

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 (a) file(s) along with optional message contents.

Refer to ChannelId::send_files for examples and more information.

The Attach Files and Send Messages permissions are required.

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

Errors

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

Sends a message to the channel with the given content.

Note: This will only work when a Message is received.

Note: Requires the Send Messages permission.

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 a ModelError::InvalidPermissions if the current user does not have the required permissions.

Unpins a Message in the channel given by its Id.

Requires the Manage Messages permission.

Retrieves the channel's webhooks.

Note: Requires the Manage Webhooks permission.

Trait Implementations

impl From<GuildChannel> for ChannelId
[src]

Gets the Id of a guild channel.

impl<'a> From<&'a GuildChannel> for ChannelId
[src]

Gets the Id of a guild channel.

impl Clone for GuildChannel
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for GuildChannel
[src]

Formats the value using the given formatter. Read more

impl Display for GuildChannel
[src]

Formats the channel, creating a mention of it.

impl Mentionable for GuildChannel
[src]

Creates a mentionable string, that will be able to notify and/or create a link to the item. Read more

Auto Trait Implementations