Table of Contents

Class SocketTextChannel

Namespace
Discord.WebSocket
Assembly
Discord.Net.WebSocket.dll

Represents a WebSocket-based channel in a guild that can send and receive messages.

public class SocketTextChannel : SocketGuildChannel, ITextChannel, IMentionable, INestedChannel, IIntegrationChannel, IGuildChannel, IDeletable, ISocketMessageChannel, IMessageChannel, IChannel, ISnowflakeEntity, IEntity<ulong>
Inheritance
SocketTextChannel
Implements
Derived
Inherited Members
Extension Methods

Properties

CachedMessages

Gets all messages in this channel's cache.

public IReadOnlyCollection<SocketMessage> CachedMessages { get; }

Property Value

IReadOnlyCollection<SocketMessage>

A read-only collection of WebSocket-based messages.

Category

Gets the parent (category) of this channel in the guild's channel list.

public ICategoryChannel Category { get; }

Property Value

ICategoryChannel

An ICategoryChannel representing the parent of this channel; null if none is set.

CategoryId

Gets the parent (category) ID of this channel in the guild's channel list.

public ulong? CategoryId { get; }

Property Value

ulong?

A ulong representing the snowflake identifier of the parent of this channel; null if none is set.

DefaultArchiveDuration

Gets the default auto-archive duration for client-created threads in this channel.

public ThreadArchiveDuration DefaultArchiveDuration { get; }

Property Value

ThreadArchiveDuration

The default auto-archive duration for thread creation in this channel.

Remarks

The value of this property does not affect API thread creation, it will not respect this value.

DefaultSlowModeInterval

Gets the current default slow-mode delay for threads in this channel.

public int DefaultSlowModeInterval { get; }

Property Value

int

An int representing the time in seconds required before the user can send another message; 0 if disabled.

IsNsfw

Gets a value that indicates whether the channel is NSFW.

public bool IsNsfw { get; }

Property Value

bool

true if the channel has the NSFW flag enabled; otherwise false.

Mention

Returns a special string used to mention this object.

public string Mention { get; }

Property Value

string

A string that is recognized by Discord as a mention (e.g. <@168693960628371456>).

SlowModeInterval

Gets the current slow-mode delay for this channel.

public virtual int SlowModeInterval { get; }

Property Value

int

An int representing the time in seconds required before the user can send another message; 0 if disabled.

Threads

Gets a collection of threads within this text channel.

public IReadOnlyCollection<SocketThreadChannel> Threads { get; }

Property Value

IReadOnlyCollection<SocketThreadChannel>

Topic

Gets the current topic for this text channel.

public string Topic { get; }

Property Value

string

A string representing the topic set in the channel; null if none is set.

Users

Gets a collection of users that are able to view the channel.

public override IReadOnlyCollection<SocketGuildUser> Users { get; }

Property Value

IReadOnlyCollection<SocketGuildUser>

A read-only collection of users that can access the channel (i.e. the users seen in the user list).

Remarks

If this channel is a voice channel, use ConnectedUsers to retrieve a collection of users who are currently connected to this channel.

Methods

CreateInviteAsync(int?, int?, bool, bool, RequestOptions)

Creates a new invite to this channel.

public virtual Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)

Parameters

maxAge int?

The time (in seconds) until the invite expires. Set to null to never expire.

maxUses int?

The max amount of times this invite may be used. Set to null to have unlimited uses.

isTemporary bool

If true, the user accepting this invite will be kicked from the guild after closing their client.

isUnique bool

If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).

options RequestOptions

The options to be used when sending the request.

Returns

Task<IInviteMetadata>

A task that represents the asynchronous invite creation operation. The task result contains an invite metadata object containing information for the created invite.

Examples

The following example creates a new invite to this channel; the invite lasts for 12 hours and can only be used 3 times throughout its lifespan.

await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3);

CreateInviteToApplicationAsync(DefaultApplications, int?, int?, bool, bool, RequestOptions)

Creates a new invite to this channel.

public virtual Task<IInviteMetadata> CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)

Parameters

application DefaultApplications

The application to open for this invite.

maxAge int?

The time (in seconds) until the invite expires. Set to null to never expire.

maxUses int?

The max amount of times this invite may be used. Set to null to have unlimited uses.

isTemporary bool

If true, the user accepting this invite will be kicked from the guild after closing their client.

isUnique bool

If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).

options RequestOptions

The options to be used when sending the request.

Returns

Task<IInviteMetadata>

A task that represents the asynchronous invite creation operation. The task result contains an invite metadata object containing information for the created invite.

CreateInviteToApplicationAsync(ulong, int?, int?, bool, bool, RequestOptions)

Creates a new invite to this channel.

public virtual Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)

Parameters

applicationId ulong

The id of the embedded application to open for this invite.

maxAge int?

The time (in seconds) until the invite expires. Set to null to never expire.

maxUses int?

The max amount of times this invite may be used. Set to null to have unlimited uses.

isTemporary bool

If true, the user accepting this invite will be kicked from the guild after closing their client.

isUnique bool

If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).

options RequestOptions

The options to be used when sending the request.

Returns

Task<IInviteMetadata>

A task that represents the asynchronous invite creation operation. The task result contains an invite metadata object containing information for the created invite.

CreateInviteToStreamAsync(IUser, int?, int?, bool, bool, RequestOptions)

Creates a new invite to this channel.

public virtual Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)

Parameters

user IUser

The id of the user whose stream to display for this invite.

maxAge int?

The time (in seconds) until the invite expires. Set to null to never expire.

maxUses int?

The max amount of times this invite may be used. Set to null to have unlimited uses.

isTemporary bool

If true, the user accepting this invite will be kicked from the guild after closing their client.

isUnique bool

If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).

options RequestOptions

The options to be used when sending the request.

Returns

Task<IInviteMetadata>

A task that represents the asynchronous invite creation operation. The task result contains an invite metadata object containing information for the created invite.

Examples

The following example creates a new invite to this channel; the invite lasts for 12 hours and can only be used 3 times throughout its lifespan.

await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3);

CreateThreadAsync(string, ThreadType, ThreadArchiveDuration, IMessage, bool?, int?, RequestOptions)

Creates a thread within this ITextChannel.

public virtual Task<SocketThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null)

Parameters

name string

The name of the thread.

type ThreadType

The type of the thread.

Note: This parameter is not used if the message parameter is not specified.

autoArchiveDuration ThreadArchiveDuration

The duration on which this thread archives after.

message IMessage

The message which to start the thread from.

invitable bool?
slowmode int?
options RequestOptions

The options to be used when sending the request.

Returns

Task<SocketThreadChannel>

A task that represents the asynchronous create operation. The task result contains a IThreadChannel

Remarks

When message is null the thread type will be based off of the channel its created in. When called on a ITextChannel, it creates a PublicThread. When called on a INewsChannel, it creates a NewsThread. The id of the created thread will be the same as the id of the message, and as such a message can only have a single thread created from it.

CreateWebhookAsync(string, Stream, RequestOptions)

Creates a webhook in this text channel.

public virtual Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)

Parameters

name string

The name of the webhook.

avatar Stream

The avatar of the webhook.

options RequestOptions

The options to be used when sending the request.

Returns

Task<RestWebhook>

A task that represents the asynchronous creation operation. The task result contains the newly created webhook.

DeleteMessageAsync(IMessage, RequestOptions)

Deletes a message based on the provided message in this channel.

public virtual Task DeleteMessageAsync(IMessage message, RequestOptions options = null)

Parameters

message IMessage

The message that would be removed.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous removal operation.

DeleteMessageAsync(ulong, RequestOptions)

Deletes a message.

public virtual Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)

Parameters

messageId ulong

The snowflake identifier of the message that would be removed.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous removal operation.

DeleteMessagesAsync(IEnumerable<IMessage>, RequestOptions)

Bulk-deletes multiple messages.

public virtual Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)

Parameters

messages IEnumerable<IMessage>

The messages to be bulk-deleted.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous bulk-removal operation.

Examples

The following example gets 250 messages from the channel and deletes them.

var messages = await textChannel.GetMessagesAsync(250).FlattenAsync();
await textChannel.DeleteMessagesAsync(messages);

Remarks

This method attempts to remove the messages specified in bulk.

important

Due to the limitation set by Discord, this method can only remove messages that are posted within 14 days!

DeleteMessagesAsync(IEnumerable<ulong>, RequestOptions)

Bulk-deletes multiple messages.

public virtual Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null)

Parameters

messageIds IEnumerable<ulong>

The snowflake identifier of the messages to be bulk-deleted.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous bulk-removal operation.

Remarks

This method attempts to remove the messages specified in bulk.

important

Due to the limitation set by Discord, this method can only remove messages that are posted within 14 days!

EnterTypingState(RequestOptions)

Continuously broadcasts the "user is typing" message to all users in this channel until the returned object is disposed.

public virtual IDisposable EnterTypingState(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

IDisposable

A disposable object that, upon its disposal, will stop the client from broadcasting its typing state in this channel.

Examples

The following example keeps the client in the typing state until LongRunningAsync has finished.

using (channel.EnterTypingState())
    await LongRunningAsync();

GetActiveThreadsAsync(RequestOptions)

Gets a collection of active threads within this channel.

public virtual Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task<IReadOnlyCollection<RestThreadChannel>>

A task that represents an asynchronous get operation for retrieving the threads. The task result contains a collection of active threads.

GetCachedMessage(ulong)

Gets a cached message from this channel.

public virtual SocketMessage GetCachedMessage(ulong id)

Parameters

id ulong

The snowflake identifier of the message.

Returns

SocketMessage

A WebSocket-based message object; null if it does not exist in the cache or if caching is not enabled.

Remarks

warning

This method requires the use of cache, which is not enabled by default; if caching is not enabled, this method will always return null. Please refer to MessageCacheSize for more details.

This method retrieves the message from the local WebSocket cache and does not send any additional request to Discord. This message may be a message that has been deleted.

GetCachedMessages(IMessage, Direction, int)

Gets the last N cached messages starting from a certain message in this message channel.

public virtual IReadOnlyCollection<SocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = 100)

Parameters

fromMessage IMessage

The message to start the fetching from.

dir Direction

The direction of which the message should be gotten from.

limit int

The number of messages to get.

Returns

IReadOnlyCollection<SocketMessage>

A read-only collection of WebSocket-based messages.

Remarks

warning

This method requires the use of cache, which is not enabled by default; if caching is not enabled, this method will always return an empty collection. Please refer to MessageCacheSize for more details.

This method retrieves the message(s) from the local WebSocket cache and does not send any additional request to Discord. This read-only collection may include messages that have been deleted. The maximum number of messages that can be retrieved from this method depends on the MessageCacheSize set.

GetCachedMessages(int)

Gets the last N cached messages from this message channel.

public virtual IReadOnlyCollection<SocketMessage> GetCachedMessages(int limit = 100)

Parameters

limit int

The number of messages to get.

Returns

IReadOnlyCollection<SocketMessage>

A read-only collection of WebSocket-based messages.

Remarks

warning

This method requires the use of cache, which is not enabled by default; if caching is not enabled, this method will always return an empty collection. Please refer to MessageCacheSize for more details.

This method retrieves the message(s) from the local WebSocket cache and does not send any additional request to Discord. This read-only collection may include messages that have been deleted. The maximum number of messages that can be retrieved from this method depends on the MessageCacheSize set.

GetCachedMessages(ulong, Direction, int)

Gets the last N cached messages starting from a certain message in this message channel.

public virtual IReadOnlyCollection<SocketMessage> GetCachedMessages(ulong fromMessageId, Direction dir, int limit = 100)

Parameters

fromMessageId ulong

The message ID to start the fetching from.

dir Direction

The direction of which the message should be gotten from.

limit int

The number of messages to get.

Returns

IReadOnlyCollection<SocketMessage>

A read-only collection of WebSocket-based messages.

Remarks

warning

This method requires the use of cache, which is not enabled by default; if caching is not enabled, this method will always return an empty collection. Please refer to MessageCacheSize for more details.

This method retrieves the message(s) from the local WebSocket cache and does not send any additional request to Discord. This read-only collection may include messages that have been deleted. The maximum number of messages that can be retrieved from this method depends on the MessageCacheSize set.

GetInvitesAsync(RequestOptions)

Gets a collection of all invites to this channel.

public virtual Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task<IReadOnlyCollection<IInviteMetadata>>

A task that represents the asynchronous get operation. The task result contains a read-only collection of invite metadata that are created for this channel.

Examples

The following example gets all of the invites that have been created in this channel and selects the most used invite.

  var invites = await channel.GetInvitesAsync();
                             if (invites.Count == 0) return;
                             var invite = invites.OrderByDescending(x => x.Uses).FirstOrDefault();

GetMessageAsync(ulong, RequestOptions)

Gets a message from this message channel.

public virtual Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null)

Parameters

id ulong

The snowflake identifier of the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IMessage>

A task that represents an asynchronous get operation for retrieving the message. The task result contains the retrieved message; null if no message is found with the specified identifier.

Remarks

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

GetMessagesAsync(IMessage, Direction, int, RequestOptions)

Gets a collection of messages in this channel.

public virtual IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null)

Parameters

fromMessage IMessage

The starting message to get the messages from.

dir Direction

The direction of the messages to be gotten from.

limit int

The numbers of message to be gotten from.

options RequestOptions

The options to be used when sending the request.

Returns

IAsyncEnumerable<IReadOnlyCollection<IMessage>>

Paged collection of messages.

Remarks

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

GetMessagesAsync(int, RequestOptions)

Gets the last N messages from this message channel.

public virtual IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = 100, RequestOptions options = null)

Parameters

limit int

The numbers of message to be gotten from.

options RequestOptions

The options to be used when sending the request.

Returns

IAsyncEnumerable<IReadOnlyCollection<IMessage>>

Paged collection of messages.

Remarks

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

GetMessagesAsync(ulong, Direction, int, RequestOptions)

Gets a collection of messages in this channel.

public virtual IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = 100, RequestOptions options = null)

Parameters

fromMessageId ulong

The ID of the starting message to get the messages from.

dir Direction

The direction of the messages to be gotten from.

limit int

The numbers of message to be gotten from.

options RequestOptions

The options to be used when sending the request.

Returns

IAsyncEnumerable<IReadOnlyCollection<IMessage>>

Paged collection of messages.

Remarks

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

GetPinnedMessagesAsync(RequestOptions)

Gets a read-only collection of pinned messages in this channel.

public virtual Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task<IReadOnlyCollection<RestMessage>>

A task that represents the asynchronous get operation for retrieving pinned messages in this channel. The task result contains a read-only collection of messages found in the pinned messages.

Remarks

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

GetUser(ulong)

public override SocketGuildUser GetUser(ulong id)

Parameters

id ulong

Returns

SocketGuildUser

GetWebhookAsync(ulong, RequestOptions)

Gets a webhook available in this text channel.

public virtual Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)

Parameters

id ulong

The identifier of the webhook.

options RequestOptions

The options to be used when sending the request.

Returns

Task<RestWebhook>

A task that represents the asynchronous get operation. The task result contains a webhook associated with the identifier; null if the webhook is not found.

GetWebhooksAsync(RequestOptions)

Gets the webhooks available in this text channel.

public virtual Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task<IReadOnlyCollection<RestWebhook>>

A task that represents the asynchronous get operation. The task result contains a read-only collection of webhooks that is available in this channel.

ModifyAsync(Action<TextChannelProperties>, RequestOptions)

Modifies this text channel.

public virtual Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null)

Parameters

func Action<TextChannelProperties>

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.

See Also

ModifyMessageAsync(ulong, Action<MessageProperties>, RequestOptions)

Modifies a message.

public virtual Task<IUserMessage> ModifyMessageAsync(ulong messageId, Action<MessageProperties> func, RequestOptions options = null)

Parameters

messageId ulong

The snowflake identifier of the message that would be changed.

func Action<MessageProperties>

A delegate containing the properties to modify the message with.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IUserMessage>

A task that represents the asynchronous modification operation.

Remarks

This method modifies this message with the specified properties. To see an example of this method and what properties are available, please refer to MessageProperties.

SendFileAsync(FileAttachment, string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties)

Sends a file to this message channel with an optional caption.

public virtual Task<RestUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, PollProperties poll = null)

Parameters

attachment FileAttachment

The attachment containing the file and description.

text string

The message to be sent.

isTTS bool

Whether the message should be read aloud by Discord or not.

embed Embed

The RichEmbed to be sent.

options RequestOptions

The options to be used when sending the request.

allowedMentions AllowedMentions

Specifies if notifications are sent for mentioned users and roles in the message text. If null, all mentioned roles and users will be notified.

messageReference MessageReference

The message references to be included. Used to reply to specific messages.

components MessageComponent

The message components to be included with this message. Used for interactions.

stickers ISticker[]

A collection of stickers to send with the file.

embeds Embed[]

A array of Embeds to send with this response. Max 10.

flags MessageFlags

A message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.

poll PollProperties

A poll to send with the message.

Returns

Task<RestUserMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Remarks

This method sends a file as if you are uploading an attachment directly from your Discord client.

note

If you wish to upload an image and have it embedded in a Rich embed, you may upload the file and refer to the file with "attachment://filename.ext" in the ImageUrl. See the example section for its usage.

Exceptions

ArgumentOutOfRangeException

Message content is too long, length must be less or equal to MaxMessageSize.

ArgumentException

The only valid MessageFlags are SuppressEmbeds, SuppressNotification and None.

SendFileAsync(Stream, string, string, bool, Embed, RequestOptions, bool, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties)

Sends a file to this message channel with an optional caption.

public virtual Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, PollProperties poll = null)

Parameters

stream Stream

The Stream of the file to be sent.

filename string

The name of the attachment.

text string

The message to be sent.

isTTS bool

Whether the message should be read aloud by Discord or not.

embed Embed

The RichEmbed to be sent.

options RequestOptions

The options to be used when sending the request.

isSpoiler bool

Whether the message attachment should be hidden as a spoiler.

allowedMentions AllowedMentions

Specifies if notifications are sent for mentioned users and roles in the message text. If null, all mentioned roles and users will be notified.

messageReference MessageReference

The message references to be included. Used to reply to specific messages.

components MessageComponent

The message components to be included with this message. Used for interactions.

stickers ISticker[]

A collection of stickers to send with the file.

embeds Embed[]

A array of Embeds to send with this response. Max 10.

flags MessageFlags

A message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.

poll PollProperties

A poll to send with the message.

Returns

Task<RestUserMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Examples

The following example uploads a streamed image that will be called b1nzy.jpg embedded inside a rich embed to the channel.

using (var b1nzyStream = await httpClient.GetStreamAsync("https://example.com/b1nzy"))
    await channel.SendFileAsync(b1nzyStream, "b1nzy.jpg",
        embed: new EmbedBuilder { ImageUrl = "attachment://b1nzy.jpg" }.Build());

Remarks

This method sends a file as if you are uploading an attachment directly from your Discord client.

note

If you wish to upload an image and have it embedded in a Rich embed, you may upload the file and refer to the file with "attachment://filename.ext" in the ImageUrl. See the example section for its usage.

Exceptions

ArgumentOutOfRangeException

Message content is too long, length must be less or equal to MaxMessageSize.

ArgumentException

The only valid MessageFlags are SuppressEmbeds, SuppressNotification and None.

SendFileAsync(string, string, bool, Embed, RequestOptions, bool, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties)

Sends a file to this message channel with an optional caption.

public virtual Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, PollProperties poll = null)

Parameters

filePath string

The file path of the file.

text string

The message to be sent.

isTTS bool

Whether the message should be read aloud by Discord or not.

embed Embed

The RichEmbed to be sent.

options RequestOptions

The options to be used when sending the request.

isSpoiler bool

Whether the message attachment should be hidden as a spoiler.

allowedMentions AllowedMentions

Specifies if notifications are sent for mentioned users and roles in the message text. If null, all mentioned roles and users will be notified.

messageReference MessageReference

The message references to be included. Used to reply to specific messages.

components MessageComponent

The message components to be included with this message. Used for interactions.

stickers ISticker[]

A collection of stickers to send with the file.

embeds Embed[]

A array of Embeds to send with this response. Max 10.

flags MessageFlags

A message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.

poll PollProperties

A poll to send with the message.

Returns

Task<RestUserMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Examples

The following example uploads a local file called wumpus.txt along with the text good discord boi to the channel.

await channel.SendFileAsync("wumpus.txt", "good discord boi");

The following example uploads a local image called b1nzy.jpg embedded inside a rich embed to the channel.

await channel.SendFileAsync("b1nzy.jpg",
    embed: new EmbedBuilder { ImageUrl = "attachment://b1nzy.jpg" }.Build());

Remarks

This method sends a file as if you are uploading an attachment directly from your Discord client.

note

If you wish to upload an image and have it embedded in a Rich embed, you may upload the file and refer to the file with "attachment://filename.ext" in the ImageUrl. See the example section for its usage.

Exceptions

ArgumentException

The only valid MessageFlags are SuppressEmbeds, SuppressNotification and None.

SendFilesAsync(IEnumerable<FileAttachment>, string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties)

Sends a collection of files to this message channel.

public virtual Task<RestUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, PollProperties poll = null)

Parameters

attachments IEnumerable<FileAttachment>

A collection of attachments to upload.

text string

The message to be sent.

isTTS bool

Whether the message should be read aloud by Discord or not.

embed Embed

The RichEmbed to be sent.

options RequestOptions

The options to be used when sending the request.

allowedMentions AllowedMentions

Specifies if notifications are sent for mentioned users and roles in the message text. If null, all mentioned roles and users will be notified.

messageReference MessageReference

The message references to be included. Used to reply to specific messages.

components MessageComponent

The message components to be included with this message. Used for interactions.

stickers ISticker[]

A collection of stickers to send with the file.

embeds Embed[]

A array of Embeds to send with this response. Max 10.

flags MessageFlags

A message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.

poll PollProperties

A poll to send with the message.

Returns

Task<RestUserMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Remarks

This method sends files as if you are uploading attachments directly from your Discord client.

note

If you wish to upload an image and have it embedded in a Rich embed, you may upload the file and refer to the file with "attachment://filename.ext" in the ImageUrl. See the example section for its usage.

Exceptions

ArgumentOutOfRangeException

Message content is too long, length must be less or equal to MaxMessageSize.

ArgumentException

The only valid MessageFlags are SuppressEmbeds, SuppressNotification and None.

SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties)

Sends a message to this message channel.

public virtual Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, PollProperties poll = null)

Parameters

text string

The message to be sent.

isTTS bool

Determines whether the message should be read aloud by Discord or not.

embed Embed

The RichEmbed to be sent.

options RequestOptions

The options to be used when sending the request.

allowedMentions AllowedMentions

Specifies if notifications are sent for mentioned users and roles in the message text. If null, all mentioned roles and users will be notified.

messageReference MessageReference

The message references to be included. Used to reply to specific messages.

components MessageComponent

The message components to be included with this message. Used for interactions.

stickers ISticker[]

A collection of stickers to send with the message.

embeds Embed[]

A array of Embeds to send with this response. Max 10.

flags MessageFlags

A message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.

poll PollProperties

A poll to send with the message.

Returns

Task<RestUserMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

Examples

The following example sends a message with the current system time in RFC 1123 format to the channel and deletes itself after 5 seconds.

var message = await channel.SendMessageAsync(DateTimeOffset.UtcNow.ToString("R"));
await Task.Delay(TimeSpan.FromSeconds(5))
    .ContinueWith(x => message.DeleteAsync());

Exceptions

ArgumentOutOfRangeException

Message content is too long, length must be less or equal to MaxMessageSize.

ArgumentException

The only valid MessageFlags are SuppressEmbeds, SuppressNotification and None.

SyncPermissionsAsync(RequestOptions)

Syncs the permissions of this nested channel with its parent's.

public virtual Task SyncPermissionsAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for syncing channel permissions with its parent's.

TriggerTypingAsync(RequestOptions)

Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds.

public virtual Task TriggerTypingAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation that triggers the broadcast.