Client - truemedian/Discordia GitHub Wiki
Inherits Emitter
The main point of entry into a Discordia application. All data relevant to Discord are accessible through a client instance or its child objects after a connection to Discord is established with the run
method. In other words, client data should not be expected and most client methods should not be called until after the ready
event is received. Base emitter methods may be called at any time.
run
stop
setUsername
setAvatar
createGuild
createGroupChannel
getWebhook
getInvite
getUser
getGuild
getChannel
getRole
getEmoji
listVoiceRegions
getConnections
setStatus
setGame
setAFKInherited from Emitter
on
once
onSync
onceSync
emit
getListeners
getListenerCount
removeListener
removeAllListeners
waitFor
shardCount
totalShardCount
user
owner
verified
mfaEnabled
guilds
users
privateChannels
groupChannels
relationships
Authenticates the current user via HTTPS and launches as many WSS gateway shards as are required or requested. By using coroutines that are automatically managed by Luvit libraries and a libuv event loop, multiple clients per process and multiple shards per client can operate concurrently. This should be the last method called after all other code and event handlers have been initialized.
Name Type Optional token string presence table x Returns: nil
Disconnects all shards and effectively stop their loops. This does not empty any data that the client may have cached.
Returns: nil
Sets the client's username. This must be between 2 and 32 characters in length. This does not change the application name.
Name Type username string Returns: boolean
Sets the client's avatar. To remove the avatar, pass an empty string or nil. This does not change the application image.
Name Type avatar Base64 Resolveable Returns: boolean
Creates a new guild. The name must be between 2 and 100 characters in length. This method may not work if the current user is in too many guilds. Note that this does not return the created guild object; listen for the corresponding
guildCreate
event if you need the object.
Name Type name string Returns: boolean
Creates a new group channel. This method is only available for user accounts.
Returns: GroupChannel
Gets a webhook object by ID. This always makes an HTTP request to obtain the object, which is a static copy of the server object; it is not automatically updated via gateway events.
Name Type id string Returns: Webhook
Gets an invite object by code. This always makes an HTTP request to obtain the object, which is a static copy of the server object; it is not automatically updated via gateway events.
Name Type Optional code string counts boolean x Returns: Invite
Gets a user object by ID. If the object is already cached, then the cached object will be returned; otherwise, an HTTP request is made. Under circumstances which should be rare, the user object may be an old version, not updated by gateway events.
Name Type id User ID Resolvable Returns: User
Gets a guild object by ID. The current user must be in the guild and the client must be running the appropriate shard that serves this guild. This method never makes an HTTP request to obtain a guild.
Name Type id Guild ID Resolvable Returns: Guild
Gets a channel object by ID. For guild channels, the current user must be in the channel's guild and the client must be running the appropriate shard that serves the channel's guild. For private channels, the channel must have been previously opened and cached. If the channel is not cached,
User:getPrivateChannel
should be used instead.
Name Type id Channel ID Resolvable Returns: Channel
Returns a raw data table that contains a list of voice regions as provided by Discord, with no additional parsing.
Name Type id Role ID Resolvable Returns: Role
Gets a user object by ID. This method nevermakes an HTTP request to obtain a guild. Under circumstances which should be rare, the user object may be an old version, not updated by gateway events.
Name Type id Emoji ID Resolvable Returns: Emoji
Returns a raw data table that contains a list of voice regions as provided by Discord, with no additional parsing.
Returns: table
Returns a raw data table that contains a list of connections as provided by Discord, with no additional parsing.
Returns: table
Sets the current users's status on all shards that are managed by this client. Valid statuses are
online
,idle
,dnd
, andinvisible
.
Name Type status string Returns: nil
Sets the current users's game on all shards that are managed by this client. If a string is passed, it is treated as the game name. If a table is passed, it must have a
name
field and may optionally have aurl
field. Passnil
to remove the game status.
Name Type game string Returns: nil
Set the current user's AFK status on all shards that are managed by this client. This generally applies to user accounts and their push notifications.
Name Type afk boolean Returns: nil
Inherited from Emitter
Subscribes a callback to be called every time the named event is emitted. Callbacks registered with this method will automatically be wrapped as a new coroutine when they are called. Returns the original callback for convenience.
Name Type name string fn function Returns: function
Subscribes a callback to be called only the first time this event is emitted. Callbacks registered with this method will automatically be wrapped as a new coroutine when they are called. Returns the original callback for convenience.
Name Type name string fn function Returns: function
Subscribes a callback to be called every time the named event is emitted. Callbacks registered with this method are not automatically wrapped as a coroutine. Returns the original callback for convenience.
Name Type name string fn function Returns: function
Subscribes a callback to be called only the first time this event is emitted. Callbacks registered with this method are not automatically wrapped as a coroutine. Returns the original callback for convenience.
Name Type name string fn function Returns: function
Emits the named event and a variable number of arguments to pass to the event callbacks.
Name Type Optional name string ... * x Returns: nil
Returns an iterator for all callbacks registered to the named event.
Name Type name string Returns: function
Returns the number of callbacks registered to the named event.
Name Type name string Returns: number
Unregisters all instances of the callback from the named event.
Name Type name string Returns: nil
Unregisters all callbacks from the named event.
Name Type name string Returns: nil
When called inside of a coroutine, this will yield the coroutine until the specific named event is emitted or until a timeout (in milliseconds) expires. If the coroutine is resumed by the event, then
true
is returned with any event arguments. If the coroutine is resumed by the timeout's expiration, thenfalse
is returned without any other arguments.
Name Type Optional Optional name string timeout number x predicate function x Returns: boolean, ...
The number of shards that this client is managing.
Type: number|nil
The total number of shards that this user is on.
Type: number|nil
User object representing the current user.
Type: User|nil
User object representing the current user's owner.
Type: User|nil
Whether the current user's owner's account is verified.
Type: boolean|nil
Whether the current user's owner's account has multi-factor (or two-factor) authentication enabled.
Type: boolean|nil
The current user's owner's account's email address (user-accounts only).
Type: string|nil
An iterable cache of all guilds that are visible to the client. Note that the guilds present here correspond to which shards the client is managing. If all shards are managed by one client, then all guilds will be present.
Type: Cache
An iterable cache of all users that are visible to the client. Users that are not referenced elsewhere are eventually garbage collected. To access a user that may exist but is not cached, use
Client:getUser
.Type: Cache
An iterable cache of all private channels that are visible to the client. The channel must exist and must be open for it to be cached here. To access a private channel that may exist but is not cached,
User:getPrivateChannel
.Type: Cache
An iterable cache of all group channels that are visible to the client. Only user-accounts should have these.
Type: Cache
An iterable cache of all relationships that are visible to the client. Only user-accounts should have these.
Type: Cache