Show / Hide Table of Contents

Class RestDMChannel

Represents a REST-based direct-message channel.

Inheritance
System.Object
RestEntity<System.UInt64>
RestChannel
RestDMChannel
Implements
IUpdateable
IDMChannel
IRestPrivateChannel
IPrivateChannel
IRestMessageChannel
IMessageChannel
IChannel
ISnowflakeEntity
IEntity<System.UInt64>
Inherited Members
RestChannel.CreatedAt
RestEntity<UInt64>.Id
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Discord.Rest
Assembly: Discord.Net.Rest.dll
Syntax
public class RestDMChannel : RestChannel, IUpdateable, IDMChannel, IRestPrivateChannel, IPrivateChannel, IRestMessageChannel, IMessageChannel, IChannel, ISnowflakeEntity, IEntity<ulong>

Properties

| Improve this Doc View Source

CurrentUser

Gets the current logged-in user.

Declaration
public RestUser CurrentUser { get; }
Property Value
Type Description
RestUser
| Improve this Doc View Source

Recipient

Gets the recipient of the channel.

Declaration
public RestUser Recipient { get; }
Property Value
Type Description
RestUser
| Improve this Doc View Source

Users

Gets a collection that is the current logged-in user and the recipient.

Declaration
public IReadOnlyCollection<RestUser> Users { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyCollection<RestUser>

Methods

| Improve this Doc View Source

CloseAsync(RequestOptions)

Closes this private channel, removing it from your channel list.

Declaration
public Task CloseAsync(RequestOptions options = null)
Parameters
Type Name Description
RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task

A task that represents the asynchronous close operation.

| Improve this Doc View Source

DeleteMessageAsync(IMessage, RequestOptions)

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

Declaration
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
Parameters
Type Name Description
IMessage message

The message that would be removed.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task

A task that represents the asynchronous removal operation.

| Improve this Doc View Source

DeleteMessageAsync(UInt64, RequestOptions)

Deletes a message.

Declaration
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
Parameters
Type Name Description
System.UInt64 messageId

The snowflake identifier of the message that would be removed.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task

A task that represents the asynchronous removal operation.

| Improve this Doc View Source

EnterTypingState(RequestOptions)

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

Declaration
public IDisposable EnterTypingState(RequestOptions options = null)
Parameters
Type Name Description
RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.IDisposable

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

| Improve this Doc View Source

GetMessageAsync(UInt64, RequestOptions)

Gets a message from this message channel.

Declaration
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
Parameters
Type Name Description
System.UInt64 id

The snowflake identifier of the message.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task<RestMessage>

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(UInt64, CacheMode, RequestOptions). Please visit its documentation for more details on this method.

| Improve this Doc View Source

GetMessagesAsync(IMessage, Direction, Int32, RequestOptions)

Gets a collection of messages in this channel.

Declaration
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null)
Parameters
Type Name Description
IMessage fromMessage

The starting message to get the messages from.

Direction dir

The direction of the messages to be gotten from.

System.Int32 limit

The numbers of message to be gotten from.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Collections.Generic.IAsyncEnumerable<System.Collections.Generic.IReadOnlyCollection<RestMessage>>

Paged collection of messages.

Remarks

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

| Improve this Doc View Source

GetMessagesAsync(Int32, RequestOptions)

Gets the last N messages from this message channel.

Declaration
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = 100, RequestOptions options = null)
Parameters
Type Name Description
System.Int32 limit

The numbers of message to be gotten from.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Collections.Generic.IAsyncEnumerable<System.Collections.Generic.IReadOnlyCollection<RestMessage>>

Paged collection of messages.

Remarks

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

| Improve this Doc View Source

GetMessagesAsync(UInt64, Direction, Int32, RequestOptions)

Gets a collection of messages in this channel.

Declaration
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = 100, RequestOptions options = null)
Parameters
Type Name Description
System.UInt64 fromMessageId

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

Direction dir

The direction of the messages to be gotten from.

System.Int32 limit

The numbers of message to be gotten from.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Collections.Generic.IAsyncEnumerable<System.Collections.Generic.IReadOnlyCollection<RestMessage>>

Paged collection of messages.

Remarks

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

| Improve this Doc View Source

GetPinnedMessagesAsync(RequestOptions)

Gets a collection of pinned messages in this channel.

Declaration
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
Parameters
Type Name Description
RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<RestMessage>>

A task that represents the asynchronous get operation for retrieving pinned messages in this channel. The task result contains a 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.

| Improve this Doc View Source

GetUser(UInt64)

Gets a user in this channel from the provided id.

Declaration
public RestUser GetUser(ulong id)
Parameters
Type Name Description
System.UInt64 id

The snowflake identifier of the user.

Returns
Type Description
RestUser

A RestUser object that is a recipient of this channel; otherwise null.

| Improve this Doc View Source

SendFileAsync(Stream, String, String, Boolean, Embed, RequestOptions, Boolean)

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

Declaration
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false)
Parameters
Type Name Description
System.IO.Stream stream

The System.IO.Stream of the file to be sent.

System.String filename

The name of the attachment.

System.String text

The message to be sent.

System.Boolean isTTS

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

Embed embed

The Rich Embed to be sent.

RequestOptions options

The options to be used when sending the request.

System.Boolean isSpoiler
Returns
Type Description
System.Threading.Tasks.Task<RestUserMessage>

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

Remarks

This method follows the same behavior as described in SendFileAsync(Stream, String, String, Boolean, Embed, RequestOptions, Boolean). Please visit its documentation for more details on this method.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

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

| Improve this Doc View Source

SendFileAsync(String, String, Boolean, Embed, RequestOptions, Boolean)

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

Declaration
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false)
Parameters
Type Name Description
System.String filePath

The file path of the file.

System.String text

The message to be sent.

System.Boolean isTTS

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

Embed embed

The Rich Embed to be sent.

RequestOptions options

The options to be used when sending the request.

System.Boolean isSpoiler
Returns
Type Description
System.Threading.Tasks.Task<RestUserMessage>

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

Remarks

This method follows the same behavior as described in SendFileAsync(String, String, Boolean, Embed, RequestOptions, Boolean). Please visit its documentation for more details on this method.

Exceptions
Type Condition
System.ArgumentException

filePath is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.GetInvalidPathChars.

System.ArgumentNullException

filePath is null.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid, (for example, it is on an unmapped drive).

System.UnauthorizedAccessException

filePath specified a directory.-or- The caller does not have the required permission.

System.IO.FileNotFoundException

The file specified in filePath was not found.

System.NotSupportedException

filePath is in an invalid format.

System.IO.IOException

An I/O error occurred while opening the file.

System.ArgumentOutOfRangeException

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

| Improve this Doc View Source

SendMessageAsync(String, Boolean, Embed, RequestOptions)

Sends a message to this message channel.

Declaration
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null)
Parameters
Type Name Description
System.String text

The message to be sent.

System.Boolean isTTS

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

Embed embed

The Rich Embed to be sent.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task<RestUserMessage>

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

Remarks

This method follows the same behavior as described in SendMessageAsync(String, Boolean, Embed, RequestOptions). Please visit its documentation for more details on this method.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

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

| Improve this Doc View Source

ToString()

Gets a string that represents the Username#Discriminator of the recipient.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string that resolves to the Recipient of this channel.

Overrides
System.Object.ToString()
| Improve this Doc View Source

TriggerTypingAsync(RequestOptions)

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

Declaration
public Task TriggerTypingAsync(RequestOptions options = null)
Parameters
Type Name Description
RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task

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

| Improve this Doc View Source

UpdateAsync(RequestOptions)

Updates this object's properties with its current state.

Declaration
public override Task UpdateAsync(RequestOptions options = null)
Parameters
Type Name Description
RequestOptions options
Returns
Type Description
System.Threading.Tasks.Task
Overrides
RestChannel.UpdateAsync(RequestOptions)

Explicit Interface Implementations

| Improve this Doc View Source

IChannel.GetUserAsync(UInt64, CacheMode, RequestOptions)

Gets a user in this channel.

Declaration
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
Parameters
Type Name Description
System.UInt64 id

The snowflake identifier of the user (e.g. 168693960628371456).

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<IUser>

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

| Improve this Doc View Source

IChannel.GetUsersAsync(CacheMode, RequestOptions)

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

Declaration
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
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<IUser>>

Paged collection of users.

Remarks
important

The returned collection is an asynchronous enumerable object; one must call FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) to access the individual messages as a collection.

This method will attempt to fetch all users that is able to view this channel or is currently in this channel. The library will attempt to split up the requests according to and MaxUsersPerBatch. In other words, if there are 3000 users, and the MaxUsersPerBatch constant is 1000, the request will be split into 3 individual requests; thus returning 53individual asynchronous responses, hence the need of flattening.
| Improve this Doc View Source

IChannel.Name

Gets the name of this channel.

Declaration
string IChannel.Name { get; }
Returns
Type Description
System.String

A string containing the name of this channel.

| Improve this Doc View Source

IDMChannel.Recipient

Gets the recipient of all messages in this channel.

Declaration
IUser IDMChannel.Recipient { get; }
Returns
Type Description
IUser

A user object that represents the other user in this channel.

| Improve this Doc View Source

IMessageChannel.GetMessageAsync(UInt64, CacheMode, RequestOptions)

Gets a message from this message channel.

Declaration
Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
Parameters
Type Name Description
System.UInt64 id

The snowflake identifier of the message.

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

| Improve this Doc View Source

IMessageChannel.GetMessagesAsync(IMessage, Direction, Int32, CacheMode, RequestOptions)

Gets a collection of messages in this channel.

Declaration
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
Parameters
Type Name Description
IMessage fromMessage

The starting message to get the messages from.

Direction dir

The direction of the messages to be gotten from.

System.Int32 limit

The numbers of message to be gotten from.

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<IMessage>>

Paged collection of messages.

Remarks
important

The returned collection is an asynchronous enumerable object; one must call FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) to access the individual messages as a collection.

warning

Do not fetch too many messages at once! This may cause unwanted preemptive rate limit or even actual rate limit, causing your bot to freeze!

This method will attempt to fetch the number of messages specified under limit around the message fromMessage depending on the dir. The library will attempt to split up the requests according to your limit and MaxMessagesPerBatch. In other words, should the user request 500 messages, and the MaxMessagesPerBatch constant is 100, the request will be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need of flattening.
| Improve this Doc View Source

IMessageChannel.GetMessagesAsync(Int32, CacheMode, RequestOptions)

Gets the last N messages from this message channel.

Declaration
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
Parameters
Type Name Description
System.Int32 limit

The numbers of message to be gotten from.

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<IMessage>>

Paged collection of messages.

Remarks
important

The returned collection is an asynchronous enumerable object; one must call FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) to access the individual messages as a collection.

warning

Do not fetch too many messages at once! This may cause unwanted preemptive rate limit or even actual rate limit, causing your bot to freeze!

This method will attempt to fetch the number of messages specified under limit. The library will attempt to split up the requests according to your limit and MaxMessagesPerBatch. In other words, should the user request 500 messages, and the MaxMessagesPerBatch constant is 100, the request will be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need of flattening.
| Improve this Doc View Source

IMessageChannel.GetMessagesAsync(UInt64, Direction, Int32, CacheMode, RequestOptions)

Gets a collection of messages in this channel.

Declaration
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
Parameters
Type Name Description
System.UInt64 fromMessageId

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

Direction dir

The direction of the messages to be gotten from.

System.Int32 limit

The numbers of message to be gotten from.

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<IMessage>>

Paged collection of messages.

Remarks
important

The returned collection is an asynchronous enumerable object; one must call FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) to access the individual messages as a collection.

warning

Do not fetch too many messages at once! This may cause unwanted preemptive rate limit or even actual rate limit, causing your bot to freeze!

This method will attempt to fetch the number of messages specified under limit around the message fromMessageId depending on the dir. The library will attempt to split up the requests according to your limit and MaxMessagesPerBatch. In other words, should the user request 500 messages, and the MaxMessagesPerBatch constant is 100, the request will be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need of flattening.
| Improve this Doc View Source

IMessageChannel.GetPinnedMessagesAsync(RequestOptions)

Gets a collection of pinned messages in this channel.

Declaration
Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
Parameters
Type Name Description
RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<IMessage>>

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

| Improve this Doc View Source

IMessageChannel.SendFileAsync(Stream, String, String, Boolean, Embed, RequestOptions, Boolean)

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

Declaration
Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler)
Parameters
Type Name Description
System.IO.Stream stream

The System.IO.Stream of the file to be sent.

System.String filename

The name of the attachment.

System.String text

The message to be sent.

System.Boolean isTTS

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

Embed embed

The Rich Embed to be sent.

RequestOptions options

The options to be used when sending the request.

System.Boolean isSpoiler

Whether the message attachment should be hidden as a spoiler.

Returns
Type Description
System.Threading.Tasks.Task<IUserMessage>

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.

| Improve this Doc View Source

IMessageChannel.SendFileAsync(String, String, Boolean, Embed, RequestOptions, Boolean)

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

Declaration
Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler)
Parameters
Type Name Description
System.String filePath

The file path of the file.

System.String text

The message to be sent.

System.Boolean isTTS

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

Embed embed

The Rich Embed to be sent.

RequestOptions options

The options to be used when sending the request.

System.Boolean isSpoiler

Whether the message attachment should be hidden as a spoiler.

Returns
Type Description
System.Threading.Tasks.Task<IUserMessage>

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.

| Improve this Doc View Source

IMessageChannel.SendMessageAsync(String, Boolean, Embed, RequestOptions)

Sends a message to this message channel.

Declaration
Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
Parameters
Type Name Description
System.String text

The message to be sent.

System.Boolean isTTS

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

Embed embed

The Rich Embed to be sent.

RequestOptions options

The options to be used when sending the request.

Returns
Type Description
System.Threading.Tasks.Task<IUserMessage>

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

| Improve this Doc View Source

IPrivateChannel.Recipients

Gets the users that can access this channel.

Declaration
IReadOnlyCollection<IUser> IPrivateChannel.Recipients { get; }
Returns
Type Description
System.Collections.Generic.IReadOnlyCollection<IUser>

A read-only collection of users that can access this channel.

| Improve this Doc View Source

IRestPrivateChannel.Recipients

Users that can access this channel.

Declaration
IReadOnlyCollection<RestUser> IRestPrivateChannel.Recipients { get; }
Returns
Type Description
System.Collections.Generic.IReadOnlyCollection<RestUser>

Implements

IUpdateable
IDMChannel
IRestPrivateChannel
IPrivateChannel
IRestMessageChannel
IMessageChannel
IChannel
ISnowflakeEntity
IEntity<TId>
  • Improve this Doc
  • View Source
Back to top Generated by DocFX