Show / Hide Table of Contents

Interface IGuildChannel

Represents a generic guild channel.

Inherited Members
IChannel.Name
ISnowflakeEntity.CreatedAt
IEntity<UInt64>.Id
IDeletable.DeleteAsync(RequestOptions)
Namespace: Discord
Assembly: Discord.Net.Core.dll
Syntax
public interface IGuildChannel : IChannel, ISnowflakeEntity, IEntity<ulong>, IDeletable

Properties

| Improve this Doc View Source

Guild

Gets the guild associated with this channel.

Declaration
IGuild Guild { get; }
Property Value
Type Description
IGuild

A guild object that this channel belongs to.

| Improve this Doc View Source

GuildId

Gets the guild ID associated with this channel.

Declaration
ulong GuildId { get; }
Property Value
Type Description
System.UInt64

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

| Improve this Doc View Source

PermissionOverwrites

Gets a collection of permission overwrites for this channel.

Declaration
IReadOnlyCollection<Overwrite> PermissionOverwrites { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyCollection<Overwrite>

A collection of overwrites associated with this channel.

| Improve this Doc View Source

Position

Gets the position of this channel.

Declaration
int Position { get; }
Property Value
Type Description
System.Int32

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

Methods

| Improve this Doc View Source

AddPermissionOverwriteAsync(IRole, OverwritePermissions, RequestOptions)

Adds or updates the permission overwrite for the given role.

Declaration
Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
Parameters
Type Name Description
IRole role

The role to add the overwrite to.

OverwritePermissions permissions

The overwrite to add to the role.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.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(UInt64) and a channel via GetChannelAsync(UInt64, 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 &amp;&amp; previousOverwrite.Value.SendMessages == PermValue.Deny)
    throw new InvalidOperationException($&quot;Role {role.Name} had already been muted in this channel.&quot;);

// 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));

}

| Improve this Doc View Source

AddPermissionOverwriteAsync(IUser, OverwritePermissions, RequestOptions)

Adds or updates the permission overwrite for the given user.

Declaration
Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
Parameters
Type Name Description
IUser user

The user to add the overwrite to.

OverwritePermissions permissions

The overwrite to add to the user.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.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(UInt64, CacheMode, RequestOptions) and a channel via GetChannelAsync(UInt64, 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 &amp;&amp; previousOverwrite.Value.SendMessages == PermValue.Deny)
    throw new InvalidOperationException($&quot;User {user.Username} had already been muted in this channel.&quot;);

// 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));

}

| Improve this Doc View Source

GetPermissionOverwrite(IRole)

Gets the permission overwrite for a specific role.

Declaration
OverwritePermissions? GetPermissionOverwrite(IRole role)
Parameters
Type Name Description
IRole role

The role to get the overwrite from.

Returns
Type Description
System.Nullable<OverwritePermissions>

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

| Improve this Doc View Source

GetPermissionOverwrite(IUser)

Gets the permission overwrite for a specific user.

Declaration
OverwritePermissions? GetPermissionOverwrite(IUser user)
Parameters
Type Name Description
IUser user

The user to get the overwrite from.

Returns
Type Description
System.Nullable<OverwritePermissions>

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

| Improve this Doc View Source

GetUserAsync(UInt64, CacheMode, RequestOptions)

Gets a user in this channel.

Declaration
Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type Name Description
System.UInt64 id

The snowflake identifier of the user.

CacheMode mode

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

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.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.

| Improve this Doc View Source

GetUsersAsync(CacheMode, RequestOptions)

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

Declaration
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type Name Description
CacheMode mode

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

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Collections.Generic.IAsyncEnumerable<System.Collections.Generic.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.

| Improve this Doc View Source

ModifyAsync(Action<GuildChannelProperties>, RequestOptions)

Modifies this guild channel.

Declaration
Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
Parameters
Type Name Description
System.Action<GuildChannelProperties> func

The delegate containing the properties to modify the channel with.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.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.

| Improve this Doc View Source

RemovePermissionOverwriteAsync(IRole, RequestOptions)

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

Declaration
Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
Parameters
Type Name Description
IRole role

The role to remove the overwrite from.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task

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

| Improve this Doc View Source

RemovePermissionOverwriteAsync(IUser, RequestOptions)

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

Declaration
Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
Parameters
Type Name Description
IUser user

The user to remove the overwrite from.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task

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

See Also

ITextChannel
IVoiceChannel
ICategoryChannel
  • Improve this Doc
  • View Source
Back to top Generated by DocFX