Table of Contents

Interface IGuildChannel

Namespace
Discord
Assembly
Discord.Net.Core.dll

Represents a generic guild channel.

public interface IGuildChannel : IChannel, ISnowflakeEntity, IEntity<ulong>, IDeletable
Inherited Members
Extension Methods

Properties

Flags

Gets the flags related to this channel.

ChannelFlags Flags { get; }

Property Value

ChannelFlags

A channel's flags, if any is associated.

Remarks

This value is determined by bitwise OR-ing ChannelFlags values together.

Guild

Gets the guild associated with this channel.

IGuild Guild { get; }

Property Value

IGuild

A guild object that this channel belongs to.

GuildId

Gets the guild ID associated with this channel.

ulong GuildId { get; }

Property Value

ulong

An ulong representing the guild snowflake identifier for the guild that this channel belongs to.

PermissionOverwrites

Gets a collection of permission overwrites for this channel.

IReadOnlyCollection<Overwrite> PermissionOverwrites { get; }

Property Value

IReadOnlyCollection<Overwrite>

A collection of overwrites associated with this channel.

Position

Gets the position of this channel.

int Position { get; }

Property Value

int

An int representing the position of this channel in the guild's channel list relative to others of the same type.

Methods

AddPermissionOverwriteAsync(IRole, OverwritePermissions, RequestOptions)

Adds or updates the permission overwrite for the given role.

Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)

Parameters

role IRole

The role to add the overwrite to.

permissions OverwritePermissions

The overwrite to add to the role.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task representing the asynchronous permission operation for adding the specified permissions to the channel.

Examples

The following example fetches a role via GetRole(ulong) and a channel via GetChannelAsync(ulong, CacheMode, RequestOptions). Next, it checks if an overwrite had already been set via GetPermissionOverwrite(IRole); if not, it denies the role from sending any messages to the channel.

public async Task MuteRoleAsync(IRole role, IGuildChannel channel)
{
    if (role == null)
        throw new ArgumentNullException(nameof(role));
    if (channel == null)
        throw new ArgumentNullException(nameof(channel));
// Fetches the previous overwrite and bail if one is found
var previousOverwrite = channel.GetPermissionOverwrite(role);
if (previousOverwrite.HasValue && previousOverwrite.Value.SendMessages == PermValue.Deny)
    throw new InvalidOperationException($"Role {role.Name} had already been muted in this channel.");

// Creates a new OverwritePermissions with send message set to deny and pass it into the method
await channel.AddPermissionOverwriteAsync(role, new OverwritePermissions(sendMessages: PermValue.Deny));

}

AddPermissionOverwriteAsync(IUser, OverwritePermissions, RequestOptions)

Adds or updates the permission overwrite for the given user.

Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)

Parameters

user IUser

The user to add the overwrite to.

permissions OverwritePermissions

The overwrite to add to the user.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task representing the asynchronous permission operation for adding the specified permissions to the channel.

Examples

The following example fetches a user via GetUserAsync(ulong, CacheMode, RequestOptions) and a channel via GetChannelAsync(ulong, CacheMode, RequestOptions). Next, it checks if an overwrite had already been set via GetPermissionOverwrite(IUser); if not, it denies the user from sending any messages to the channel.

public async Task MuteUserAsync(IGuildUser user, IGuildChannel channel)
{
    if (user == null)
        throw new ArgumentNullException(nameof(user));
    if (channel == null)
        throw new ArgumentNullException(nameof(channel));
// Fetches the previous overwrite and bail if one is found
var previousOverwrite = channel.GetPermissionOverwrite(user);
if (previousOverwrite.HasValue && previousOverwrite.Value.SendMessages == PermValue.Deny)
    throw new InvalidOperationException($"User {user.Username} had already been muted in this channel.");

// Creates a new OverwritePermissions with send message set to deny and pass it into the method
await channel.AddPermissionOverwriteAsync(user, new OverwritePermissions(sendMessages: PermValue.Deny));

}

GetPermissionOverwrite(IRole)

Gets the permission overwrite for a specific role.

OverwritePermissions? GetPermissionOverwrite(IRole role)

Parameters

role IRole

The role to get the overwrite from.

Returns

OverwritePermissions?

An overwrite object for the targeted role; null if none is set.

GetPermissionOverwrite(IUser)

Gets the permission overwrite for a specific user.

OverwritePermissions? GetPermissionOverwrite(IUser user)

Parameters

user IUser

The user to get the overwrite from.

Returns

OverwritePermissions?

An overwrite object for the targeted user; null if none is set.

GetUserAsync(ulong, CacheMode, RequestOptions)

Gets a user in this channel.

Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

id ulong

The snowflake identifier of the user.

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IGuildUser>

A task representing the asynchronous get operation. The task result contains a guild user object that represents the user; null if none is found.

GetUsersAsync(CacheMode, RequestOptions)

Gets a collection of users that are able to view the channel or are currently in this channel.

IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

IAsyncEnumerable<IReadOnlyCollection<IGuildUser>>

Paged collection of users.

Remarks

This method follows the same behavior as described in GetUsersAsync(CacheMode, RequestOptions). Please visit its documentation for more details on this method.

ModifyAsync(Action<GuildChannelProperties>, RequestOptions)

Modifies this guild channel.

Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)

Parameters

func Action<GuildChannelProperties>

The delegate containing the properties to modify the channel with.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous modification operation.

Remarks

This method modifies the current guild channel with the specified properties. To see an example of this method and what properties are available, please refer to GuildChannelProperties.

RemovePermissionOverwriteAsync(IRole, RequestOptions)

Removes the permission overwrite for the given role, if one exists.

Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)

Parameters

role IRole

The role to remove the overwrite from.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task representing the asynchronous operation for removing the specified permissions from the channel.

RemovePermissionOverwriteAsync(IUser, RequestOptions)

Removes the permission overwrite for the given user, if one exists.

Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)

Parameters

user IUser

The user to remove the overwrite from.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task representing the asynchronous operation for removing the specified permissions from the channel.

See Also