Class KookSocketClient
Represents a WebSocket-based KOOK client.
Inherited Members
Namespace: Kook.WebSocket
Assembly: Kook.Net.WebSocket.dll
Syntax
public class KookSocketClient : BaseSocketClient, IKookClient, IDisposable
Constructors
KookSocketClient()
Initializes a new REST/WebSocket-based Kook client.
Declaration
public KookSocketClient()
KookSocketClient(KookSocketConfig)
Initializes a new REST/WebSocket-based Kook client with the provided configuration.
Declaration
public KookSocketClient(KookSocketConfig config)
Parameters
KookSocketConfig
config
The configuration to be used with the client. |
Properties
ConnectionState
Gets the current state of connection.
Declaration
public ConnectionState ConnectionState { get; }
Property Value
ConnectionState
|
Implements
DMChannels
Gets a collection of direct message channels opened in this session.
Declaration
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.
Declaration
public override IReadOnlyCollection<SocketGuild> Guilds { get; }
Property Value
IReadOnlyCollection<SocketGuild>
A read-only collection of guilds that the current user is in. |
Overrides
Latency
Gets the estimated round-trip latency, in milliseconds, to the gateway server.
Declaration
public override int Latency { get; protected set; }
Property Value
Int32
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. |
Overrides
Rest
Provides access to a REST-only client with a shared state from this client.
Declaration
public override KookSocketRestClient Rest { get; }
Property Value
KookSocketRestClient
|
Overrides
Methods
DownloadBoostSubscriptionsAsync(IEnumerable<IGuild>, RequestOptions)
Downloads all boost subscriptions for the specified guilds.
Declaration
public override Task DownloadBoostSubscriptionsAsync(IEnumerable<IGuild> guilds = null, RequestOptions options = null)
Parameters
IEnumerable<IGuild>
guilds
The guilds to download the boost subscriptions for. If |
RequestOptions
options
The options to be used when sending the request. |
Returns
Task
|
Overrides
DownloadUsersAsync(IEnumerable<IGuild>, RequestOptions)
Downloads all users for the specified guilds.
Declaration
public override Task DownloadUsersAsync(IEnumerable<IGuild> guilds = null, RequestOptions options = null)
Parameters
IEnumerable<IGuild>
guilds
The guilds to download the users for. If |
RequestOptions
options
The options to be used when sending the request. |
Returns
Task
|
Overrides
DownloadVoiceStatesAsync(IEnumerable<IGuild>, RequestOptions)
Downloads all voice states for the specified guilds.
Declaration
public override Task DownloadVoiceStatesAsync(IEnumerable<IGuild> guilds = null, RequestOptions options = null)
Parameters
IEnumerable<IGuild>
guilds
The guilds to download the voice states for. If |
RequestOptions
options
The options to be used when sending the request. |
Returns
Task
|
Overrides
GetChannel(UInt64)
Gets a channel.
Declaration
public override SocketChannel GetChannel(ulong id)
Parameters
UInt64
id
The identifier of the channel. |
Returns
SocketChannel
A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier;
|
Overrides
GetChannelAsync(UInt64, RequestOptions)
Gets a generic channel from the cache or does a rest request if unavailable.
Declaration
public Task<IChannel> GetChannelAsync(ulong id, RequestOptions options = null)
Parameters
UInt64
id
The identifier of the channel. |
RequestOptions
options
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; |
GetDMChannel(Guid)
Gets a channel.
Declaration
public override SocketDMChannel GetDMChannel(Guid chatCode)
Parameters
Guid
chatCode
The chat code of the direct-message channel. |
Returns
SocketDMChannel
A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier;
|
Overrides
GetDMChannel(UInt64)
Gets a channel.
Declaration
public override SocketDMChannel GetDMChannel(ulong userId)
Parameters
UInt64
userId
The user identifier of the direct-message channel. |
Returns
SocketDMChannel
A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier;
|
Overrides
GetDMChannelAsync(Guid, RequestOptions)
Gets a direct message channel from the cache or does a rest request if unavailable.
Declaration
public Task<IDMChannel> GetDMChannelAsync(Guid chatCode, RequestOptions options = null)
Parameters
Guid
chatCode
The identifier of the channel. |
RequestOptions
options
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; |
GetDMChannelsAsync(RequestOptions)
Gets a collection of direct message channels from the cache or does a rest request if unavailable.
Declaration
public Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(RequestOptions options = null)
Parameters
RequestOptions
options
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; |
GetGuild(UInt64)
Gets a guild.
Declaration
public override SocketGuild GetGuild(ulong id)
Parameters
UInt64
id
The guild identifier. |
Returns
SocketGuild
A WebSocket-based guild associated with the identifier; |
Overrides
GetUser(String, String)
Gets a user.
Declaration
public override SocketUser GetUser(string username, string identifyNumber)
Parameters
String
username
The name of the user. |
String
identifyNumber
The identify value of the user. |
Returns
SocketUser
A generic WebSocket-based user; |
Overrides
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
GetUser(UInt64)
Gets a generic user.
Declaration
public override SocketUser GetUser(ulong id)
Parameters
UInt64
id
The user ID. |
Returns
SocketUser
A generic WebSocket-based user; |
Overrides
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(UInt64, RequestOptions)
Gets a user from the cache or does a rest request if unavailable.
Declaration
public Task<IUser> GetUserAsync(ulong id, RequestOptions options = null)
Parameters
UInt64
id
The identifier of the user (e.g. |
RequestOptions
options
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; |
StartAsync()
Starts the WebSocket connection.
Declaration
public override Task StartAsync()
Returns
Task
A task that represents the asynchronous start operation. |
Overrides
StopAsync()
Stops the WebSocket connection.
Declaration
public override Task StopAsync()
Returns
Task
A task that represents the asynchronous stop operation. |
Overrides
Events
Connected
Fired when connected to the Kook gateway.
Declaration
public event Func<Task> Connected
Event Type
Func<Task>
|
Disconnected
Fired when disconnected to the Kook gateway.
Declaration
public event Func<Exception, Task> Disconnected
Event Type
Func<Exception, Task>
|
LatencyUpdated
Fired when a heartbeat is received from the Kook gateway.
Declaration
public event Func<int, int, Task> LatencyUpdated
Event Type
Func<Int32, Int32, Task>
|
Ready
Fired when guild data has finished downloading.
Declaration
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.