Search Results for

    Show / Hide Table of Contents

    Interface IMessageChannel

    Represents a generic channel that can send and receive messages.

    Inherited Members
    IChannel.Name
    IChannel.GetUsersAsync(CacheMode, RequestOptions)
    IChannel.GetUserAsync(UInt64, CacheMode, RequestOptions)
    ISnowflakeEntity.CreatedAt
    IEntity<UInt64>.Id
    Namespace: Discord
    Assembly: Discord.Net.Core.dll
    Syntax
    public interface IMessageChannel : IChannel, ISnowflakeEntity, IEntity<ulong>

    Methods

    | Improve this Doc View Source

    DeleteMessageAsync(IMessage, RequestOptions)

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

    Declaration
    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
    Task

    A task that represents the asynchronous removal operation.

    | Improve this Doc View Source

    DeleteMessageAsync(UInt64, RequestOptions)

    Deletes a message.

    Declaration
    Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
    Parameters
    Type Name Description
    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
    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
    IDisposable EnterTypingState(RequestOptions options = null)
    Parameters
    Type Name Description
    RequestOptions options

    The options to be used when sending the request.

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

    | Improve this Doc View Source

    GetMessageAsync(UInt64, CacheMode, RequestOptions)

    Gets a message from this message channel.

    Declaration
    Task<IMessage> GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
    Parameters
    Type Name Description
    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
    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

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

    Gets a collection of messages in this channel.

    Declaration
    IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = null, CacheMode mode = CacheMode.AllowDownload, 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.

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

    Examples

    The following example gets 5 message prior to a specific message, oldMessage.

    | Improve this Doc View Source

    GetMessagesAsync(Int32, CacheMode, RequestOptions)

    Gets the last N messages from this message channel.

    Declaration
    IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = null, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
    Parameters
    Type Name Description
    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
    IAsyncEnumerable<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.

    Examples

    The following example downloads 300 messages and gets messages that belong to the user 53905483156684800.

    | Improve this Doc View Source

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

    Gets a collection of messages in this channel.

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

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

    Direction dir

    The direction of the messages to be gotten from.

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

    Examples

    The following example gets 5 message prior to the message identifier 442012544660537354.

    The following example attempts to retrieve messageCount number of messages from the beginning of the channel and prints them to the console.

    | Improve this Doc View Source

    GetPinnedMessagesAsync(RequestOptions)

    Gets a collection of pinned messages in this channel.

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

    The options to be used when sending the request.

    Returns
    Type Description
    Task<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

    ModifyMessageAsync(UInt64, Action<MessageProperties>, RequestOptions)

    Modifies a message.

    Declaration
    Task<IUserMessage> ModifyMessageAsync(ulong messageId, Action<MessageProperties> func, RequestOptions options = null)
    Parameters
    Type Name Description
    UInt64 messageId

    The snowflake identifier of the message that would be changed.

    Action<MessageProperties> func

    A delegate containing the properties to modify the message with.

    RequestOptions options

    The options to be used when sending the request.

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

    | Improve this Doc View Source

    SendFileAsync(FileAttachment, String, Boolean, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)

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

    Declaration
    Task<IUserMessage> 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 = default(MessageFlags))
    Parameters
    Type Name Description
    FileAttachment attachment

    The attachment containing the file and description.

    String text

    The message to be sent.

    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.

    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.

    MessageComponent components

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

    ISticker[] stickers

    A collection of stickers to send with the file.

    Embed[] embeds

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

    MessageFlags flags

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

    Returns
    Type Description
    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

    SendFileAsync(Stream, String, String, Boolean, Embed, RequestOptions, Boolean, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)

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

    Declaration
    Task<IUserMessage> 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 = default(MessageFlags))
    Parameters
    Type Name Description
    Stream stream

    The of the file to be sent.

    String filename

    The name of the attachment.

    String text

    The message to be sent.

    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.

    Boolean isSpoiler

    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.

    MessageComponent components

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

    ISticker[] stickers

    A collection of stickers to send with the file.

    Embed[] embeds

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

    MessageFlags flags

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

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

    Examples

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

    | Improve this Doc View Source

    SendFileAsync(String, String, Boolean, Embed, RequestOptions, Boolean, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)

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

    Declaration
    Task<IUserMessage> 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 = default(MessageFlags))
    Parameters
    Type Name Description
    String filePath

    The file path of the file.

    String text

    The message to be sent.

    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.

    Boolean isSpoiler

    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.

    MessageComponent components

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

    ISticker[] stickers

    A collection of stickers to send with the file.

    Embed[] embeds

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

    MessageFlags flags

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

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

    Examples

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

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

    | Improve this Doc View Source

    SendFilesAsync(IEnumerable<FileAttachment>, String, Boolean, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)

    Sends a collection of files to this message channel.

    Declaration
    Task<IUserMessage> 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 = default(MessageFlags))
    Parameters
    Type Name Description
    IEnumerable<FileAttachment> attachments

    A collection of attachments to upload.

    String text

    The message to be sent.

    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.

    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.

    MessageComponent components

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

    ISticker[] stickers

    A collection of stickers to send with the file.

    Embed[] embeds

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

    MessageFlags flags

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

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

    | Improve this Doc View Source

    SendMessageAsync(String, Boolean, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)

    Sends a message to this message channel.

    Declaration
    Task<IUserMessage> 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 = default(MessageFlags))
    Parameters
    Type Name Description
    String text

    The message to be sent.

    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.

    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.

    MessageComponent components

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

    ISticker[] stickers

    A collection of stickers to send with the message.

    Embed[] embeds

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

    MessageFlags flags

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

    Returns
    Type Description
    Task<IUserMessage>

    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.

    | Improve this Doc View Source

    TriggerTypingAsync(RequestOptions)

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

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

    The options to be used when sending the request.

    Returns
    Type Description
    Task

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

    Extension Methods

    ChannelExtensions.GetChannelType(IChannel)

    Theme

    • Improve this Doc
    • View Source
    In This Article
    Back to top Discord.Net (c) 2015-2022 3.6.0