Table of Contents

Interface IMessageChannel

Namespace
Kook
Assembly
Kook.Net.Core.dll

表示一个通用的消息频道,可以用来发送和接收消息。

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

Methods

DeleteMessageAsync(IMessage, RequestOptions?)

删除一条消息.

Task DeleteMessageAsync(IMessage message, RequestOptions? options = null)

Parameters

message IMessage

要删除的消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task

一个表示异步删除操作的任务。

DeleteMessageAsync(Guid, RequestOptions?)

删除一条消息。

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

Parameters

messageId Guid

要删除的消息的 ID。

options RequestOptions

发送请求时要使用的选项。

Returns

Task

一个表示异步删除操作的任务。

GetMessageAsync(Guid, CacheMode, RequestOptions?)

从此消息频道获取一条消息。

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

Parameters

id Guid

消息的 ID。

mode CacheMode

指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<IMessage>

一个表示异步获取操作的任务。任务结果包含检索到的消息;如果未找到具有指定 ID 的消息,则返回 null

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

获取此消息频道中的一些消息。

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

Parameters

referenceMessage IMessage

要开始获取消息的参考位置的消息。

dir Direction

要以参考位置为基准,获取消息的方向。

limit int

要获取的消息数量。

mode CacheMode

指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。

options RequestOptions

发送请求时要使用的选项。

Returns

IAsyncEnumerable<IReadOnlyCollection<IMessage>>

分页的消息集合的异步可枚举对象。

Remarks

important

返回的集合是一个异步可枚举对象;调用 FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) 可以异步枚举所有分页,并将其合并为一个集合。


warning

请勿一次性获取过多消息,这可能会导致抢占式速率限制,甚至触发实际的速率限制,从而导致 Bot 服务暂停。


此方法将尝试获取此频道最新的 limit 条消息。此方法会根据 MaxMessagesPerBatch 将请求拆分。换句话说,如果要获取 500 条消息,而 MaxMessagesPerBatch 的常量为 50,则请求将被拆分为 10 个单独请求,因此异步枚举器会异步枚举返回 10 个响应。 FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) 方法可以展开这 10 个响应返回的集合,并将其合并为一个集合。

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

获取此消息频道中的一些消息。

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

Parameters

referenceMessageId Guid

要开始获取消息的参考位置的消息的 ID。

dir Direction

要以参考位置为基准,获取消息的方向。

limit int

要获取的消息数量。

mode CacheMode

指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。

options RequestOptions

发送请求时要使用的选项。

Returns

IAsyncEnumerable<IReadOnlyCollection<IMessage>>

分页的消息集合的异步可枚举对象。

Remarks

important

返回的集合是一个异步可枚举对象;调用 FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) 可以异步枚举所有分页,并将其合并为一个集合。


warning

请勿一次性获取过多消息,这可能会导致抢占式速率限制,甚至触发实际的速率限制,从而导致 Bot 服务暂停。


此方法将尝试获取此频道最新的 limit 条消息。此方法会根据 MaxMessagesPerBatch 将请求拆分。换句话说,如果要获取 500 条消息,而 MaxMessagesPerBatch 的常量为 50,则请求将被拆分为 10 个单独请求,因此异步枚举器会异步枚举返回 10 个响应。 FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) 方法可以展开这 10 个响应返回的集合,并将其合并为一个集合。

GetMessagesAsync(int, CacheMode, RequestOptions?)

获取此消息频道中的最新的一些消息。

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

Parameters

limit int

要获取的消息数量。

mode CacheMode

指示当前方法是否应该仅从缓存中获取结果,还是可以通过 API 请求获取数据。

options RequestOptions

发送请求时要使用的选项。

Returns

IAsyncEnumerable<IReadOnlyCollection<IMessage>>

分页的消息集合的异步可枚举对象。

Remarks

important

返回的集合是一个异步可枚举对象;调用 FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) 可以异步枚举所有分页,并将其合并为一个集合。


warning

请勿一次性获取过多消息,这可能会导致抢占式速率限制,甚至触发实际的速率限制,从而导致 Bot 服务暂停。


此方法将尝试获取此频道最新的 limit 条消息。此方法会根据 MaxMessagesPerBatch 将请求拆分。换句话说,如果要获取 500 条消息,而 MaxMessagesPerBatch 的常量为 50,则请求将被拆分为 10 个单独请求,因此异步枚举器会异步枚举返回 10 个响应。 FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) 方法可以展开这 10 个响应返回的集合,并将其合并为一个集合。

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

修改一条消息。

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

Parameters

messageId Guid

要修改的消息的 ID。

func Action<MessageProperties>

一个包含修改消息属性的委托。

options RequestOptions

发送请求时要使用的选项。

Returns

Task

一个表示异步修改操作的任务。

See Also

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

发送卡片消息到此消息频道。

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

Parameters

card ICard

要发送的卡片。

quote IQuote

消息引用,用于回复消息。

ephemeralUser IUser

临时消息的接收者。如果设置为指定的用户,则仅该用户可以看到此消息,否则所有人都可以看到此消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<Cacheable<IUserMessage, Guid>>

一个表示异步发送操作的任务。任务的结果包含所发送消息的可延迟加载的消息对象。

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

发送卡片消息到此消息频道。

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

Parameters

cards IEnumerable<ICard>

要发送的卡片。

quote IQuote

消息引用,用于回复消息。

ephemeralUser IUser

临时消息的接收者。如果设置为指定的用户,则仅该用户可以看到此消息,否则所有人都可以看到此消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<Cacheable<IUserMessage, Guid>>

一个表示异步发送操作的任务。任务的结果包含所发送消息的可延迟加载的消息对象。

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

发送文件到此消息频道。

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

Parameters

attachment FileAttachment

文件的附件信息。

quote IQuote

消息引用,用于回复消息。

ephemeralUser IUser

临时消息的接收者。如果设置为指定的用户,则仅该用户可以看到此消息,否则所有人都可以看到此消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<Cacheable<IUserMessage, Guid>>

一个表示异步发送操作的任务。任务的结果包含所发送消息的可延迟加载的消息对象。

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

发送文件到此消息频道。

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

文件的流。

filename string

文件名。

type AttachmentType

文件的媒体类型。

quote IQuote

消息引用,用于回复消息。

ephemeralUser IUser

临时消息的接收者。如果设置为指定的用户,则仅该用户可以看到此消息,否则所有人都可以看到此消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<Cacheable<IUserMessage, Guid>>

一个表示异步发送操作的任务。任务的结果包含所发送消息的可延迟加载的消息对象。

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

发送文件到此消息频道。

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

文件的路径。

filename string

文件名。

type AttachmentType

文件的媒体类型。

quote IQuote

消息引用,用于回复消息。

ephemeralUser IUser

临时消息的接收者。如果设置为指定的用户,则仅该用户可以看到此消息,否则所有人都可以看到此消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<Cacheable<IUserMessage, Guid>>

一个表示异步发送操作的任务。任务的结果包含所发送消息的可延迟加载的消息对象。

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

发送文本消息到此消息频道。

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

Parameters

text string

要发送的文本。

quote IQuote

消息引用,用于回复消息。

ephemeralUser IUser

临时消息的接收者。如果设置为指定的用户,则仅该用户可以看到此消息,否则所有人都可以看到此消息。

options RequestOptions

发送请求时要使用的选项。

Returns

Task<Cacheable<IUserMessage, Guid>>

一个表示异步发送操作的任务。任务的结果包含所发送消息的可延迟加载的消息对象。