Client

Client

new Client(options)

Source:
Discord Client constructor
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
token String The token of the account you wish to log in with.
autorun Boolean <optional>
If true, the client runs when constructed without calling `.connect()`.
messageCacheLimit Number <optional>
The amount of messages to cache in memory, per channel. Used for information on deleted/updated messages. The default is 50.
shard Array.<Number> <optional>
The shard array. The first index is the current shard ID, the second is the amount of shards that should be running.

Methods

connect()

Source:
Manually initiate the WebSocket connection to Discord.
Example
client.connect();

disconnect()

Source:
Disconnect the WebSocket connection to Discord.
Example
client.disconnect();

getUser(input)

Source:
Retrieve a user object from Discord, Bot only endpoint. You don't have to share a server with this user.
Example
client.getUser({
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
userID Snowflake

editUserInfo(input)

Source:
Edit the client's user information.
Example
client.editUserInfo({
	avatar: String<Base64>,
	username: String,
	email: String,
	password: String,
	new_password: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
avatar String.<Base64> The last part of a Base64 Data URI. `fs.readFileSync('image.jpg', 'base64')` is enough.
username String A username.
email String [User only] An email.
password String [User only] Your current password.
new_password String [User only] A new password.

setPresence(input)

Source:
Change the client's presence.
Example
client.setPresence({
	idle_since: Number|null,
	game: Object|null,
	game.name: String|null,
	game.type: Number|null,
	game.url: String|null,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
idle_since Number | null Use a Number before the current point in time.
game Object | null Used to set game information.
Properties
Name Type Description
name String | null The name of the game.
type Number | null Streaming activity, 0 for nothing, 1 for Twitch.
url String | null A URL matching the streaming service you've selected.

getOauthInfo()

Source:
Receive OAuth information for the current client.
Example
client.getOauthInfo();

getAccountSettings()

Source:
Receive account settings information for the current client.
Example
client.getAccountSettings();

uploadFile(input)

Source:
Upload a file to a channel.
Example
client.uploadFile({
	to: Snowflake,
	file: Buffer|String,
	filename: String|null,
	message: String|null,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
to Snowflake The target Channel or User ID.
file Buffer | String A Buffer containing the file data, or a String that's a path to the file.
filename String | null A filename for the uploaded file, required if you provide a Buffer.
message String | null An optional message to provide.

sendMessage(input)

Source:
Send a message to a channel.
Example
client.sendMessage({
	to: Snowflake,
	message: String,
	[embed]: Object,
	[tts]: Boolean,
	[nonce]: Number,
	[typing]: Boolean,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
to Snowflake The target Channel or User ID.
message String The message content.
embed Object <optional>
An embed object to include
tts Boolean <optional>
Enable Text-to-Speech for this message.
nonce Number <optional>
Number-used-only-ONCE. The Discord client uses this to change the message color from grey to white.
typing Boolean <optional>
Indicates whether the message should be sent with simulated typing. Based on message length.

getMessage(input)

Source:
Pull a message object from Discord.
Example
client.getMessage({
	channelID: Snowflake,
	messageID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake The channel ID that the message is from.
messageID Snowflake The ID of the message.

getMessages(input)

Source:
Pull an array of message objects from Discord.
Example
client.getMessages({
	channelID: Snowflake,
	[limit]: Number,
	[before]: Snowflake,
	[after]: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake The channel ID to pull the messages from.
limit Number <optional>
How many messages to pull, defaults to 50.
before Snowflake <optional>
Pull messages before this message ID.
after Snowflake <optional>
Pull messages after this message ID.

editMessage(input)

Source:
Edit a previously sent message.
Example
client.editMessage({
	channelID: Snowflake,
	messageID: Snowflake,
	message: String,
	[embed]: Object,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake
messageID Snowflake
message String The new message content
embed Object <optional>
The new Discord Embed object

deleteMessage(input)

Source:
Delete a posted message.
Example
client.deleteMessage({
	channelID: Snowflake,
	messageID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake
messageID Snowflake

deleteMessages(input)

Source:
Delete a batch of messages.
Example
client.deleteMessages({
	channelID: Snowflake,
	messageIDs: Array<Snowflake>,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake
messageIDs Array.<Snowflake> An Array of message IDs, with a maximum of 100 indexes.

pinMessage(input)

Source:
Pin a message to the channel.
Example
client.pinMessage({
	channelID: Snowflake,
	messageID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake
messageID Snowflake

getPinnedMessages(input)

Source:
Get an array of pinned messages from a channel.
Example
client.getPinnedMessages({
	channelID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake

deletePinnedMessage(input)

Source:
Delete a pinned message from a channel.
Example
client.deletePinnedMessage({
	channelID: Snowflake,
	messageID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake
messageID Snowflake

simulateTyping(channelID)

Source:
Send 'typing...' status to a channel
Example
client.simulateTyping(channelID: Snowflake);
Parameters:
Name Type Description
channelID Snowflake

fixMessage(message)

Source:
Replace Snowflakes with the names if applicable.
Example
client.fixMessage(message: String);
Parameters:
Name Type Description
message String The message to fix.

addReaction(input)

Source:
Add an emoji reaction to a message.
Example
client.addReaction({
	channelID: Snowflake,
	messageID: Snowflake,
	reaction: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake
messageID Snowflake
reaction String Either the emoji unicode or the emoji name:id/object.

getReaction(input)

Source:
Get an emoji reaction of a message.
Example
client.getReaction({
	channelID: Snowflake,
	messageID: Snowflake,
	reaction: String,
	[limit]: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake
messageID Snowflake
reaction String Either the emoji unicode or the emoji name:id/object.
limit String <optional>

removeReaction(input)

Source:
Remove an emoji reaction from a message.
Example
client.removeReaction({
	channelID: Snowflake,
	messageID: Snowflake,
	[userID]: Snowflake,
	reaction: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake
messageID Snowflake
userID Snowflake <optional>
reaction String Either the emoji unicode or the emoji name:id/object.

removeAllReactions(input)

Source:
Remove all emoji reactions from a message.
Example
client.removeAllReactions({
	channelID: Snowflake,
	messageID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
channelID Snowflake
messageID Snowflake

kick(input)

Source:
Remove a user from a server.
Example
client.kick({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

ban(input)

Source:
Remove and ban a user from a server.
Example
client.ban({
	serverID: Snowflake,
	userID: Snowflake,
	[lastDays]: Number,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
serverID Snowflake
userID Snowflake
lastDays Number <optional>
Removes their messages up until this point, either 1 or 7 days.

unban(input)

Source:
Unban a user from a server.
Example
client.unban({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

moveUserTo(input)

Source:
Move a user between voice channels.
Example
client.moveUserTo({
	serverID: Snowflake,
	userID: Snowflake,
	channelID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake
channelID Snowflake

mute(input)

Source:
Server-mute the user from speaking in all voice channels.
Example
client.mute({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

unmute(input)

Source:
Remove the server-mute from a user.
Example
client.unmute({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

deafen(input)

Source:
Server-deafan a user.
Example
client.deafen({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

undeafen(input)

Source:
Remove the server-deafan from a user.
Example
client.undeafen({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

createServer(input)

Source:
Create a server [User only].
Example
client.createServer({
	name: String,
	[region]: String,
	[icon]: String<Base64>,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
name String The server's name
region String <optional>
The server's region code, check the Gitbook documentation for all of them.
icon String.<Base64> <optional>
The last part of a Base64 Data URI. `fs.readFileSync('image.jpg', 'base64')` is enough.

editServer(input)

Source:
Edit server information.
Example
client.editServer({
	serverID: Snowflake,
	[name]: String,
	[icon]: String,
	[region]: String,
	[afk_channel_id]: Snowflake,
	[afk_timeout]: Number,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
serverID Snowflake
name String <optional>
icon String <optional>
region String <optional>
afk_channel_id Snowflake <optional>
The ID of the voice channel to move a user to after the afk period.
afk_timeout Number <optional>
Time in seconds until a user is moved to the afk channel. 60, 300, 900, 1800, or 3600.

editServerWidget(input)

Source:
Edit the widget information for a server.
Example
client.editServerWidget({
	serverID: Snowflake,
	[enabled]: Boolean,
	[channelID]: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
serverID Snowflake The ID of the server whose widget you want to edit.
enabled Boolean <optional>
Whether or not you want the widget to be enabled.
channelID Snowflake <optional>
[Important] The ID of the channel you want the instant invite to point to.

addServerEmoji(input)

Source:
[User Account] Add an emoji to a server
Example
client.addServerEmoji({
	serverID: Snowflake,
	name: String,
	image: String<Base64>,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
name String The emoji's name
image String.<Base64> The emoji's image data in Base64

editServerEmoji(input)

Source:
[User Account] Edit a server emoji data (name only, currently)
Example
client.editServerEmoji({
	serverID: Snowflake,
	emojiID: Snowflake,
	[name]: String,
	[roles]: Array<Snowflake>,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
serverID Snowflake
emojiID Snowflake The emoji's ID
name String <optional>
roles Array.<Snowflake> <optional>
An array of role IDs you want to limit the emoji's usage to

deleteServerEmoji(input)

Source:
[User Account] Remove an emoji from a server
Example
client.deleteServerEmoji({
	serverID: Snowflake,
	emojiID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
emojiID Snowflake

leaveServer(serverID)

Source:
Leave a server.
Example
client.leaveServer(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

deleteServer(serverID)

Source:
Delete a server owned by the client.
Example
client.deleteServer(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

transferOwnership(input)

Source:
Transfer ownership of a server to another user.
Example
client.transferOwnership({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

acceptInvite()

Source:
Deprecated:
  • Yes
(Used to) Accept an invite to a server [User Only]. Can no longer be used.
Example
client.acceptInvite();

createInvite()

Source:
Deprecated:
  • Yes
(Used to) Generate an invite URL for a channel.
Example
client.createInvite();

deleteInvite(inviteCode)

Source:
Delete an invite code.
Example
client.deleteInvite(inviteCode: String);
Parameters:
Name Type Description
inviteCode String

queryInvite(inviteCode)

Source:
Get information on an invite.
Example
client.queryInvite(inviteCode: String);
Parameters:
Name Type Description
inviteCode String

getServerInvites(serverID)

Source:
Get all invites for a server.
Example
client.getServerInvites(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

getChannelInvites(channelID)

Source:
Get all invites for a channel.
Example
client.getChannelInvites(channelID: Snowflake);
Parameters:
Name Type Description
channelID Snowflake

createChannel(input)

Source:
Create a channel.
Example
client.createChannel({
	serverID: Snowflake,
	name: String,
	[type]: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
serverID Snowflake
name String
type String <optional>
'text' or 'voice', defaults to 'text.

createDMChannel(userID)

Source:
Create a Direct Message channel.
Example
client.createDMChannel(userID: Snowflake);
Parameters:
Name Type Description
userID Snowflake

deleteChannel(channelID)

Source:
Delete a channel.
Example
client.deleteChannel(channelID: Snowflake);
Parameters:
Name Type Description
channelID Snowflake

editChannelInfo(input)

Source:
Edit a channel's information.
Example
client.editChannelInfo({
	channelID: Snowflake,
	[name]: String,
	[topic]: String,
	[bitrate]: Number,
	[position]: Number,
	[user_limit]: Number,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake
name String <optional>
topic String <optional>
The topic of the channel.
bitrate Number <optional>
[Voice Only] The bitrate for the channel.
position Number <optional>
The channel's position on the list.
user_limit Number <optional>
[Voice Only] Imposes a user limit on a voice channel.

editChannelPermissions(input)

Source:
Edit (or creates) a permission override for a channel.
Example
client.editChannelPermissions({
	channelID: Snowflake,
	[userID]: Snowflake,
	[roleID]: Snowflake,
	allow: Array<Number>,
	deny: Array<Number>,
	default: Array<Number>,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake
userID Snowflake <optional>
roleID Snowflake <optional>
allow Array.<Number> An array of permissions to allow. Discord.Permissions.XXXXXX.
deny Array.<Number> An array of permissions to deny, same as above.
default Array.<Number> An array of permissions that cancels out allowed and denied permissions.

deleteChannelPermission(input)

Source:
Delete a permission override for a channel.
Example
client.deleteChannelPermission({
	channelID: Snowflake,
	[userID]: Snowflake,
	[roleID]: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
channelID Snowflake
userID Snowflake <optional>
roleID Snowflake <optional>

createRole(serverID)

Source:
Create a role for a server.
Example
client.createRole(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

editRole(input)

Source:
Edit a role.
Example
client.editRole({
	serverID: Snowflake,
	roleID: Snowflake,
	[name]: String,
	[color]: String,
	[hoist]: Boolean,
	[permissions]: Object,
	[mentionable]: Boolean,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
serverID Snowflake
roleID Snowflake The ID of the role.
name String <optional>
color String <optional>
A color value as a number. Recommend using Hex numbers, as they can map to HTML colors (0xF35353 === #F35353).
hoist Boolean <optional>
Separates the users in this role from the normal online users.
permissions Object <optional>
An Object containing the permission as a key, and `true` or `false` as its value. Read the Permissions doc.
mentionable Boolean <optional>
Toggles if users can @Mention this role.

deleteRole(input)

Source:
Delete a role.
Example
client.deleteRole({
	serverID: Snowflake,
	roleID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
roleID Snowflake

addToRole(input)

Source:
Add a user to a role.
Example
client.addToRole({
	serverID: Snowflake,
	roleID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
roleID Snowflake
userID Snowflake

removeFromRole(input)

Source:
Remove a user from a role.
Example
client.removeFromRole({
	serverID: Snowflake,
	roleID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
roleID Snowflake
userID Snowflake

editNickname(input)

Source:
Edit a user's nickname.
Example
client.editNickname({
	serverID: Snowflake,
	userID: Snowflake,
	nick: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake
nick String The nickname you'd like displayed.

editNote(input)

Source:
Edit a user's note.
Example
client.editNote({
	userID: Snowflake,
	note: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
userID Snowflake
note String The note content that you want to use.

getMember(input)

Source:
Retrieve a user object from Discord, the library already caches users, however.
Example
client.getMember({
	serverID: Snowflake,
	userID: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Description
serverID Snowflake
userID Snowflake

getMembers(input)

Source:
Retrieve a group of user objects from Discord.
Example
client.getMembers({
	[limit]: Number,
	[after]: Snowflake,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
limit Number <optional>
The amount of users to pull, defaults to 50.
after Snowflake <optional>
The offset using a user ID.

getBans(serverID)

Source:
Get the ban list from a server
Example
client.getBans(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

getServerWebhooks(serverID)

Source:
Get all webhooks for a server
Example
client.getServerWebhooks(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

getChannelWebhooks(channelID)

Source:
Get webhooks from a channel
Example
client.getChannelWebhooks(channelID: Snowflake);
Parameters:
Name Type Description
channelID Snowflake

createWebhook(serverID)

Source:
Create a webhook for a server
Example
client.createWebhook(serverID: Snowflake);
Parameters:
Name Type Description
serverID Snowflake

editWebhook(input)

Source:
Edit a webhook
Example
client.editWebhook({
	webhookID: Snowflake,
	[name]: String,
	[avatar]: String<Base64>,
	[channelID]: String,
});
Parameters:
Name Type Description
input Object
Properties
Name Type Attributes Description
webhookID Snowflake The Webhook's ID
name String <optional>
avatar String.<Base64> <optional>
channelID String <optional>

joinVoiceChannel(channelID)

Source:
Join a voice channel.
Example
client.joinVoiceChannel(channelID: Snowflake);
Parameters:
Name Type Description
channelID Snowflake

leaveVoiceChannel(channelID)

Source:
Leave a voice channel.
Example
client.leaveVoiceChannel(channelID: Snowflake);
Parameters:
Name Type Description
channelID Snowflake

getAudioContext(channelObj)

Source:
Prepare the client for sending/receiving audio.
Example
client.getAudioContext(channelObj: Snowflake|Object
Parameters:
Name Type Description
channelObj Snowflake | Object Either the channel ID, or an Object with `channelID` as a key and the ID as the value.
Properties
Name Type Attributes Description
maxStreamSize Number <optional>
The size in KB that you wish to receive before pushing out earlier data. Required if you want to store or receive incoming audio.
stereo Boolean <optional>
Sets the audio to be either stereo or mono. Defaults to true.

getAllUsers()

Source:
Retrieves all offline (and online, if using a user account) users, fires the `allUsers` event when done.
Example
client.getAllUsers();