Table of Contents

Interface IMessageChannel

Namespace
Kook
Assembly
Kook.Net.Core.dll

Represents a channel that can send and receive messages.

public interface IMessageChannel : IChannel, IEntity<ulong>
Inherited Members
Extension Methods

Methods

DeleteMessageAsync(IMessage, RequestOptions?)

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

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(Guid, RequestOptions?)

Deletes a message.

Task DeleteMessageAsync(Guid messageId, RequestOptions? options = null)

Parameters

messageId Guid

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

GetMessageAsync(Guid, CacheMode, RequestOptions?)

Gets a message from this message channel.

Task<IMessage?> GetMessageAsync(Guid id, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null)

Parameters

id Guid

The identifier of the message.

mode CacheMode

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

options RequestOptions

The options to be used when sending the request.

Returns

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

GetMessagesAsync(IMessage, Direction, int, CacheMode, RequestOptions?)

Gets a collection of messages in this channel.

IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage referenceMessage, Direction dir, int limit = 50, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null)

Parameters

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

mode CacheMode

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

options RequestOptions

The options to be used when sending the request.

Returns

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

GetMessagesAsync(Guid, Direction, int, CacheMode, RequestOptions?)

Gets a collection of messages in this channel.

IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(Guid referenceMessageId, Direction dir, int limit = 50, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null)

Parameters

referenceMessageId Guid

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.

mode CacheMode

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

options RequestOptions

The options to be used when sending the request.

Returns

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

GetMessagesAsync(int, CacheMode, RequestOptions?)

Gets the last N messages from this message channel.

IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = 50, CacheMode mode = CacheMode.AllowDownload, RequestOptions? options = null)

Parameters

limit int

The numbers of message to be gotten from.

mode CacheMode

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

options RequestOptions

The options to be used when sending the request.

Returns

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

ModifyMessageAsync(Guid, Action<MessageProperties>, RequestOptions?)

Modifies a message.

Task ModifyMessageAsync(Guid messageId, Action<MessageProperties> func, RequestOptions? options = null)

Parameters

messageId Guid

The 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

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.

SendCardAsync(ICard, IQuote?, IUser?, RequestOptions?)

Sends a card message to this message channel.

Task<Cacheable<IUserMessage, Guid>> SendCardAsync(ICard card, IQuote? quote = null, IUser? ephemeralUser = null, RequestOptions? options = null)

Parameters

card ICard

The card to be sent.

quote IQuote

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

ephemeralUser IUser

The user only who can see the message. Leave null to let everyone see the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<Cacheable<IUserMessage, Guid>>

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

SendCardsAsync(IEnumerable<ICard>, IQuote?, IUser?, RequestOptions?)

Sends a card message to this message channel.

Task<Cacheable<IUserMessage, Guid>> SendCardsAsync(IEnumerable<ICard> cards, IQuote? quote = null, IUser? ephemeralUser = null, RequestOptions? options = null)

Parameters

cards IEnumerable<ICard>

The cards to be sent.

quote IQuote

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

ephemeralUser IUser

The user only who can see the message. Leave null to let everyone see the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<Cacheable<IUserMessage, Guid>>

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

SendFileAsync(FileAttachment, IQuote?, IUser?, RequestOptions?)

Sends a file to this message channel.

Task<Cacheable<IUserMessage, Guid>> SendFileAsync(FileAttachment attachment, IQuote? quote = null, IUser? ephemeralUser = null, RequestOptions? options = null)

Parameters

attachment FileAttachment

The attachment containing the file.

quote IQuote

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

ephemeralUser IUser

The user only who can see the message. Leave null to let everyone see the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<Cacheable<IUserMessage, Guid>>

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

Remarks

This method sends a file as if you are uploading a file directly from your Kook client.

SendFileAsync(Stream, string, AttachmentType, IQuote?, IUser?, RequestOptions?)

Sends a file to this message channel.

Task<Cacheable<IUserMessage, Guid>> SendFileAsync(Stream stream, string filename, AttachmentType type = AttachmentType.File, IQuote? quote = null, IUser? ephemeralUser = null, RequestOptions? options = null)

Parameters

stream Stream

The stream of the file.

filename string

The name of the file.

type AttachmentType

The type of the file.

quote IQuote

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

ephemeralUser IUser

The user only who can see the message. Leave null to let everyone see the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<Cacheable<IUserMessage, Guid>>

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

Remarks

This method sends a file as if you are uploading a file directly from your Kook client.

SendFileAsync(string, string?, AttachmentType, IQuote?, IUser?, RequestOptions?)

Sends a file to this message channel.

Task<Cacheable<IUserMessage, Guid>> SendFileAsync(string path, string? filename = null, AttachmentType type = AttachmentType.File, IQuote? quote = null, IUser? ephemeralUser = null, RequestOptions? options = null)

Parameters

path string

The file path of the file.

filename string

The name of the file.

type AttachmentType

The type of the file.

quote IQuote

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

ephemeralUser IUser

The user only who can see the message. Leave null to let everyone see the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<Cacheable<IUserMessage, Guid>>

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

Remarks

This method sends a file as if you are uploading a file directly from your Kook client.

SendTextAsync(string, IQuote?, IUser?, RequestOptions?)

Sends a text message to this message channel.

Task<Cacheable<IUserMessage, Guid>> SendTextAsync(string text, IQuote? quote = null, IUser? ephemeralUser = null, RequestOptions? options = null)

Parameters

text string

The message to be sent.

quote IQuote

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

ephemeralUser IUser

The user only who can see the message. Leave null to let everyone see the message.

options RequestOptions

The options to be used when sending the request.

Returns

Task<Cacheable<IUserMessage, Guid>>

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