Kook.Net 文档
Search Results for

    Show / Hide Table of Contents

    Class KookSocketClient

    Represents a WebSocket-based KOOK client.

    Inheritance
    Object
    BaseKookClient
    BaseSocketClient
    KookSocketClient
    Inherited Members
    BaseSocketClient._baseConfig
    BaseSocketClient.CurrentUser
    BaseSocketClient.ChannelCreated
    BaseSocketClient.ChannelDestroyed
    BaseSocketClient.ChannelUpdated
    BaseSocketClient.ReactionAdded
    BaseSocketClient.ReactionRemoved
    BaseSocketClient.DirectReactionAdded
    BaseSocketClient.DirectReactionRemoved
    BaseSocketClient.MessageReceived
    BaseSocketClient.MessageDeleted
    BaseSocketClient.MessageUpdated
    BaseSocketClient.MessagePinned
    BaseSocketClient.MessageUnpinned
    BaseSocketClient.DirectMessageReceived
    BaseSocketClient.DirectMessageDeleted
    BaseSocketClient.DirectMessageUpdated
    BaseSocketClient.UserJoined
    BaseSocketClient.UserLeft
    BaseSocketClient.UserBanned
    BaseSocketClient.UserUnbanned
    BaseSocketClient.UserUpdated
    BaseSocketClient.CurrentUserUpdated
    BaseSocketClient.GuildMemberUpdated
    BaseSocketClient.GuildMemberOnline
    BaseSocketClient.GuildMemberOffline
    BaseSocketClient.UserConnected
    BaseSocketClient.UserDisconnected
    BaseSocketClient.RoleCreated
    BaseSocketClient.RoleDeleted
    BaseSocketClient.RoleUpdated
    BaseSocketClient.EmoteCreated
    BaseSocketClient.EmoteDeleted
    BaseSocketClient.EmoteUpdated
    BaseSocketClient.JoinedGuild
    BaseSocketClient.LeftGuild
    BaseSocketClient.GuildUpdated
    BaseSocketClient.GuildAvailable
    BaseSocketClient.GuildUnavailable
    BaseSocketClient.MessageButtonClicked
    BaseSocketClient.DirectMessageButtonClicked
    BaseKookClient.Log
    BaseKookClient.LoggedIn
    BaseKookClient.LoggedOut
    BaseKookClient.LoginState
    BaseKookClient.TokenType
    BaseKookClient.Dispose()
    BaseKookClient.LoginAsync(TokenType, String, Boolean)
    BaseKookClient.LogoutAsync()
    BaseKookClient.IKookClient.ConnectionState
    BaseKookClient.IKookClient.CurrentUser
    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
    IKookClient.ConnectionState

    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
    BaseSocketClient.Guilds

    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
    BaseSocketClient.Latency

    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
    BaseSocketClient.Rest

    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 null, all available guilds will be downloaded. To download all boost subscriptions, the current user must has the ManageGuild permission.

    RequestOptions options

    The options to be used when sending the request.

    Returns
    Task

    Overrides
    BaseSocketClient.DownloadBoostSubscriptionsAsync(IEnumerable<IGuild>, RequestOptions)

    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 null, all available guilds will be downloaded.

    RequestOptions options

    The options to be used when sending the request.

    Returns
    Task

    Overrides
    BaseSocketClient.DownloadUsersAsync(IEnumerable<IGuild>, RequestOptions)

    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 null, all available guilds will be downloaded.

    RequestOptions options

    The options to be used when sending the request.

    Returns
    Task

    Overrides
    BaseSocketClient.DownloadVoiceStatesAsync(IEnumerable<IGuild>, RequestOptions)

    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; null when the channel cannot be found.

    Overrides
    BaseSocketClient.GetChannel(UInt64)

    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; null when the channel cannot be found.

    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; null when the channel cannot be found.

    Overrides
    BaseSocketClient.GetDMChannel(Guid)

    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; null when the channel cannot be found.

    Overrides
    BaseSocketClient.GetDMChannel(UInt64)

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

    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; null when the channel cannot be found.

    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; null when the guild cannot be found.

    Overrides
    BaseSocketClient.GetGuild(UInt64)

    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; null when the user cannot be found.

    Overrides
    BaseSocketClient.GetUser(String, String)
    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; null when the user cannot be found.

    Overrides
    BaseSocketClient.GetUser(UInt64)
    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. 168693960628371456).

    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; null if the user is not found.

    StartAsync()

    Starts the WebSocket connection.

    Declaration
    public override Task StartAsync()
    Returns
    Task

    A task that represents the asynchronous start operation.

    Overrides
    BaseSocketClient.StartAsync()

    StopAsync()

    Stops the WebSocket connection.

    Declaration
    public override Task StopAsync()
    Returns
    Task

    A task that represents the asynchronous stop operation.

    Overrides
    BaseSocketClient.StopAsync()

    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.

    Back to top Kook.Net (c) 2022-2023