Table of Contents

Class KookSocketClient

Namespace
Kook.WebSocket
Assembly
Kook.Net.WebSocket.dll

Represents a WebSocket-based KOOK client.

public class KookSocketClient : BaseSocketClient, IKookClient, IDisposable
Inheritance
KookSocketClient
Implements
Inherited Members
Extension Methods

Constructors

KookSocketClient()

Initializes a new REST/WebSocket-based Kook client.

public KookSocketClient()

KookSocketClient(KookSocketConfig)

Initializes a new REST/WebSocket-based Kook client with the provided configuration.

public KookSocketClient(KookSocketConfig config)

Parameters

config KookSocketConfig

The configuration to be used with the client.

Properties

ConnectionState

Gets the current state of connection.

public override ConnectionState ConnectionState { get; }

Property Value

ConnectionState

DMChannels

Gets a collection of direct message channels opened in this session.

public IReadOnlyCollection<SocketDMChannel> DMChannels { get; }

Property Value

IReadOnlyCollection<SocketDMChannel>

A collection of DM channels that have been opened in this session.

Remarks

This method returns a collection of currently opened direct message channels.

warning

This method will not return previously opened DM channels outside of the current session! If you have just started the client, this may return an empty collection.

Guilds

Gets a collection of guilds that the user is currently in.

public override IReadOnlyCollection<SocketGuild> Guilds { get; }

Property Value

IReadOnlyCollection<SocketGuild>

A read-only collection of guilds that the current user is in.

Latency

Gets the estimated round-trip latency, in milliseconds, to the gateway server.

public override int Latency { get; protected set; }

Property Value

int

An int that represents the round-trip latency to the WebSocket server. Please note that this value does not represent a "true" latency for operations such as sending a message.

Rest

Provides access to a REST-only client with a shared state from this client.

public override KookSocketRestClient Rest { get; }

Property Value

KookSocketRestClient

Methods

DownloadBoostSubscriptionsAsync(IEnumerable<IGuild>, RequestOptions)

Downloads all boost subscriptions for the specified guilds.

public override Task DownloadBoostSubscriptionsAsync(IEnumerable<IGuild> guilds = null, RequestOptions options = null)

Parameters

guilds IEnumerable<IGuild>

The guilds to download the boost subscriptions for. If null, all available guilds will be downloaded. To download all boost subscriptions, the current user must has the ManageGuild permission.

options RequestOptions

The options to be used when sending the request.

Returns

Task

DownloadUsersAsync(IEnumerable<IGuild>, RequestOptions)

Downloads all users for the specified guilds.

public override Task DownloadUsersAsync(IEnumerable<IGuild> guilds = null, RequestOptions options = null)

Parameters

guilds IEnumerable<IGuild>

The guilds to download the users for. If null, all available guilds will be downloaded.

options RequestOptions

The options to be used when sending the request.

Returns

Task

DownloadVoiceStatesAsync(IEnumerable<IGuild>, RequestOptions)

Downloads all voice states for the specified guilds.

public override Task DownloadVoiceStatesAsync(IEnumerable<IGuild> guilds = null, RequestOptions options = null)

Parameters

guilds IEnumerable<IGuild>

The guilds to download the voice states for. If null, all available guilds will be downloaded.

options RequestOptions

The options to be used when sending the request.

Returns

Task

GetChannel(ulong)

Gets a channel.

public override SocketChannel GetChannel(ulong id)

Parameters

id ulong

The identifier of the channel.

Returns

SocketChannel

A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier; null when the channel cannot be found.

GetChannelAsync(ulong, RequestOptions)

Gets a generic channel from the cache or does a rest request if unavailable.

public Task<IChannel> GetChannelAsync(ulong id, RequestOptions options = null)

Parameters

id ulong

The identifier of the channel.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IChannel>

A task that represents the asynchronous get operation. The task result contains the channel associated with the identifier; null when the channel cannot be found.

GetDMChannel(Guid)

Gets a channel.

public override SocketDMChannel GetDMChannel(Guid chatCode)

Parameters

chatCode Guid

The chat code of the direct-message channel.

Returns

SocketDMChannel

A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier; null when the channel cannot be found.

GetDMChannel(ulong)

Gets a channel.

public override SocketDMChannel GetDMChannel(ulong userId)

Parameters

userId ulong

The user identifier of the direct-message channel.

Returns

SocketDMChannel

A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier; null when the channel cannot be found.

GetDMChannelAsync(Guid, RequestOptions)

Gets a direct message channel from the cache or does a rest request if unavailable.

public Task<IDMChannel> GetDMChannelAsync(Guid chatCode, RequestOptions options = null)

Parameters

chatCode Guid

The identifier of the channel.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IDMChannel>

A task that represents the asynchronous get operation. The task result contains the channel associated with the identifier; null when the channel cannot be found.

GetDMChannelsAsync(RequestOptions)

Gets a collection of direct message channels from the cache or does a rest request if unavailable.

public Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task<IReadOnlyCollection<IDMChannel>>

A task that represents the asynchronous get operation. The task result contains the channel associated with the identifier; null when the channel cannot be found.

GetGuild(ulong)

Gets a guild.

public override SocketGuild GetGuild(ulong id)

Parameters

id ulong

The guild identifier.

Returns

SocketGuild

A WebSocket-based guild associated with the identifier; null when the guild cannot be found.

GetUser(string, string)

Gets a user.

public override SocketUser GetUser(string username, string identifyNumber)

Parameters

username string

The name of the user.

identifyNumber string

The identify value of the user.

Returns

SocketUser

A generic WebSocket-based user; null when the user cannot be found.

Remarks

This method gets the user present in the WebSocket cache with the given condition.

warning

Sometimes a user may return null due to Kook not sending offline users in large guilds (i.e. guild with 100+ members) actively. To download users on startup and to see more information about this subject, see AlwaysDownloadUsers.

note

This method does not attempt to fetch users that the logged-in user does not have access to (i.e. users who don't share mutual guild(s) with the current user). If you wish to get a user that you do not have access to, consider using the REST implementation of GetUserAsync(ulong, RequestOptions).

GetUser(ulong)

Gets a generic user.

public override SocketUser GetUser(ulong id)

Parameters

id ulong

The user ID.

Returns

SocketUser

A generic WebSocket-based user; null when the user cannot be found.

Remarks

This method gets the user present in the WebSocket cache with the given condition.

warning

Sometimes a user may return null due to Kook not sending offline users in large guilds (i.e. guild with 100+ members) actively. To download users on startup and to see more information about this subject, see AlwaysDownloadUsers.

note

This method does not attempt to fetch users that the logged-in user does not have access to (i.e. users who don't share mutual guild(s) with the current user). If you wish to get a user that you do not have access to, consider using the REST implementation of GetUserAsync(ulong, RequestOptions).

GetUserAsync(ulong, RequestOptions)

Gets a user from the cache or does a rest request if unavailable.

public Task<IUser> GetUserAsync(ulong id, RequestOptions options = null)

Parameters

id ulong

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

options RequestOptions

The options to be used when sending the request.

Returns

Task<IUser>

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

StartAsync()

Starts the WebSocket connection.

public override Task StartAsync()

Returns

Task

A task that represents the asynchronous start operation.

StopAsync()

Stops the WebSocket connection.

public override Task StopAsync()

Returns

Task

A task that represents the asynchronous stop operation.

Events

Connected

Fired when connected to the Kook gateway.

public event Func<Task> Connected

Event Type

Func<Task>

Disconnected

Fired when disconnected to the Kook gateway.

public event Func<Exception, Task> Disconnected

Event Type

Func<Exception, Task>

LatencyUpdated

Fired when a heartbeat is received from the Kook gateway.

public event Func<int, int, Task> LatencyUpdated

Event Type

Func<int, int, Task>

Ready

Fired when guild data has finished downloading.

public event Func<Task> Ready

Event Type

Func<Task>

Remarks

warning

Because guilds may contain a large amount of members, this event will not wait for all users, subscriptions, and voice states to be downloaded. It will only wait for guilds, channels, roles, and emojis to be downloaded.