Discord Js
Discord Js
Discord Js
js Documentation
Release 8.2.0
hydrabolt
i
ii
CHAPTER 1
The docs hosted here are for the discord.js v8.2 branch otherwise known as discordv8. There is a different discord.js
v11 branch and if you are on a discord server for discord.js that is probably the one you are using.
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
discordv8 is an easy-to-use and intuitive JavaScript API for Discord. It’s fairly high level, so if you’re looking for
something low level, check out discord.io. If you are looking for something fast check out eris
if you’re having problems, check out the troubleshooting guide
Feel free to make any contributions you want, whether it be through creating an issue, giving a suggestion or making
a pull request!
Note: This documentation is still a work-in-progress, apologies if something isn’t yet documented!
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
Warning: When installing with any of these methods, you’ll encounter some errors. This is because an
optional dependency isn’t working properly, but discordv8 should still work fine.
1
discord.js Documentation, Release 8.2.0
1.1.1 Windows
$ sudo add-apt-repository ppa:mc3man/trusty-media && sudo apt-get update && sudo apt-
˓→get install ffmpeg
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
If you’re coming from versions below v5, you might find some changes. Here are the major changes:
1.2.1 Change 1
// OLD:
client.getUser();
client.getServer();
server.getMember(); // etc etc
// NEW:
client.users.get();
client.servers.get();
client.members.get();
1.2.2 Change 2
// OLD:
});
// NEW:
});
1.2.3 Change 3
The Member Class has been removed, meaning you can’t use member.permissionsIn(channel). To get
permissions, use channel.permissionsOf(user).
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.3 Troubleshooting
1.3.1 General
Occasionally, the API can stop working for whatever reason. If it was working previously and it stopped working
on the same version, it means that either we screwed code up or there’s been a change to the Discord API. You can
try asking around in the ‘discord.js channel in the API server‘_. You could also make an issue if one relating to
a similar issue doesn’t exist. Please post a stacktrace if there is one, and be as detailed as possible - “the API isn’t
working” doesn’t help at all.
If there is already an issue, feel free to comment that you’re also experiencing the same thing. This helps to see how
widespread the bug is.
You can try reconnecting before submitting an issue, as sometimes some of the servers may be slightly different.
1.3. Troubleshooting 3
discord.js Documentation, Release 8.2.0
If you’re your bot or client is exiting unexpectedly with no error, this is likely caused by websocket disconnects. Make
sure you have autoReconnect enabled. See Client.
1.3.2 Voice
Often, especially if you’re on Windows, voice will not work out of the box. Follow the steps below, one by one.
• Is your system supported? The following are:
– Linux x64 & ia32
– Linux ARM (Raspberry Pi 1 & 2)
– Mac OS X x64
– Windows x64
• Did you install Python 2.7.x correctly? Is it in your PATH? python -V. If not, install it correctly or try reinstalling.
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
Not all of these are standalone examples, many of them are usage examples. If you’re a beginner to discordv8, we
encourage you to look through these examples to get a hang of the way things work using the library.
Warning: Please do not copy/paste code directly from these examples. Try to learn from and adapt these pieces
of code to your specific situation.
Note: We use Template Literals in these examples. These are an ES6 feature and may not be fully supported in your
environment. In this case, it is safe to use other methods of concatenating strings.
1.4.1 Logging In
Logs the Client in, allowing you to begin working with the Discord API.
Do not use a normal user account for large or public bots. This is considered abuse of the API and can land you
in trouble.
You can get your bot’s token using the My Applications page on the Discord Developers site.
client.loginWithToken('token', output);
The logOut function should be used if you intend to reconnect with the same process. The function takes one parame-
ter, which is a callback.
client.logOut((err) => {
console.log(err);
});
However, if you want to completely shut down your application, use destroy.
client.destroy((err) => {
console.log(err);
});
Here we will demonstrate receiving messages and logging them to the console.
client.on('message', function(message) {
if (message.channel.isPrivate) {
console.log(`(Private) ${message.author.name}: ${message.content}`);
} else {
console.log(`(${message.server.name} / ${message.channel.name}) $
˓→{message.author.name}: ${message.content}`);
}
});
This is by far the most common way people will send a message in the Discord API. Here we will send a message to
the same Channel we received a message from in the above example.
client.on('message', function(message) {
// Don't forget to log the message!
client.sendMessage(message.channel, "Hello!");
});
You can also use a Message resolvable as an parameter. This example does the same thing as above.
client.on('message', function(message) {
client.sendMessage(message, "Hello!");
});
You can also directly reply to messages. This does the same as adding an @mention in front of your text.
Sends “@author Hello!”
client.on('message', function(message) {
client.reply(message, "Hello!");
});
Sends “Hello” to the default Channel in the Server “My Server”. Note that this does not require any sort of received
message to be activated, however if there are multiple servers with the name “My Server”, a random one will be
chosen.
See Cache for more details on getting specific objects and resolvables.
Private Messages
You can also send private messages to a user with a User object. This will send “Hello!” as a private message to the
original author of the received message.
Do note however, that a PMChannel is not the same as a ServerChannel and therefore does not have the same properties
such as server and name.
client.on('message', function(message) {
client.sendMessage(message.author, "Hello!");
});
URL
client.on('message', function(message) {
client.sendFile(message, 'http://i.imgur.com/6CbxaPc.jpg', 'kappa.jpg',
˓→'Check out this cool file!', (err, m) => {
if (err) console.log(err);
});
});
Local file
client.on('message', function(message) {
client.sendFile(message, '/assets/dank_meme.jpg', 'dank_meme.jpg', 'Check out
˓→this cool file!', (err, m) => {
if (err) console.log(err);
});
});
Buffer
client.on('message', function(message) {
var stream = fs.createReadStream('/assets/dank_meme.jpg');
var chunks = [];
stream.on('data', (dataChunk) => {
chunks.push(dataChunk);
});
stream.on('end' () => {
client.sendFile(message, Buffer.concat(chunks), 'dank_meme.jpg',
˓→'Check out this cool file!');
});
});
The deleteMessage function takes an Message Resolvable as the first parameter. The second parameter is a callback.
This snippet will delete the received message.
client.on('message', function(message) {
client.deleteMessage(message);
});
You can also delete multiple messages with the deleteMessages function. It takes an array of Message Resolvable s.
This code deletes all the messages recieved every 10 seconds.
var messages = [];
client.on('message', function(message) {
messages.push(message);
});
function clear() {
client.deleteMessages(messages);
messages = [];
}
setInterval(clear, 10000);
client.on('ready', () => {
client.setStatus('online', 'Call of Duty: Black Ops 10');
});
You can also use the setPlayingGame function, if you just want to set your game...
client.on('ready', () => {
client.setPlayingGame('Call of Duty: Black Ops 10');
});
client.on('ready', () => {
client.setStatusIdle(); // Now idle
setTimeout(() => { client.setStatusOnline(); }, 10000); // Set the status
˓→back to online after 10 seconds.
});
Set streaming
client.on('ready', () => {
client.setStreaming('Call of Duty: Black Ops 10', 'https://www.twitch.tv/lirik
˓→', 1);
});
client.on('ready', () => {
var opts = {
name: 'Call of Duty: Black Ops 10',
url: 'https://www.twitch.tv/lirik',
type: 1
};
client.setStatus(null, opts);
});
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.5 Client
extends EventEmitter
This page contains documentation on the Discord.Client class. This should be used when you want to start creating
things with the API.
1.5.1 Parameters
autoReconnect
erlpack
Send and recieve data in etf format, (more efficient and faster), requires installing erlpack with npm install abalaba-
haha/erlpack
zlib
compress
forceFetchUsers
Make the library get all the users in all guilds, and delay the ready event until all users are received. This will slow
down ready times and increase initial network traffic.
guildCreateTimeout
How long in milliseconds to wait for more guilds during the initial ready stream. Default is 1000ms. Increase this
number if you are getting some serverCreated events right after ready.
largeThreshold
Set a custom large_threshold (the max number of offline members Discord sends in the initial GUILD_CREATE). The
maximum is 250.
maxCachedMessages
The maximum number of messages to cache per channel. Decreasing this leads to more missing messageUp-
dated/messageDeleted events, increasing this leads to more RAM usage, especially over time.
rateLimitAsError
Have the lib throw a rejection Promise/callback when being ratelimited, instead of auto-retrying.
disableEveryone
Have the lib insert a zero width space between here and everyone mentions disabling them.
shardCount
shardId
bot
Boolean. Use ‘Bot my_token’ when authorizing. Default is true, should be false if user bot.
1.5.2 Attributes
users
channels
privateChannels
A Cache of PMChannel objects that the client has cached. These are all the Private/Direct Chats the client is in.
1.5. Client 11
discord.js Documentation, Release 8.2.0
servers
unavailableServers
A Cache of Server objects that the client has cached that are unavailable.
voiceConnections
voiceConnection
readyTime
uptime
A Number in milliseconds representing how long the Client has been ready for.
user
userAgent
An object containing url, version and full. Setting this property allows the discord developers to keep track of active
bots, it defaults to the discordv8 git repo and the current version of the package. url should be the repository/homepage
of the creator. version should be the version of your bot. full is read only and will be automatically generated upon
setting.
1.5.3 Functions
Note: Any functions used here that take callbacks as an optional parameter can also be used as Promises. Promises
take the exact same parameters for each use case, except errors are moved to catch statements instead of then. For
example, you can do:
bot.login(email, password).then(success).catch(err);
function success(token){
// handle success
}
function err(error){
// handle error
}
or use callbacks:
Logs the client in so it can begin initialising. Use this after registering your events to ensure they are called!
• email - The e-mail used to sign in, String.
• password - The password used to sign in, String.
• callback - function that takes the following parameters:
– error - An error if any occurred
– token - The token received after logging in, String.
Logs the client in, using just a token. The specified email and password are optional - they’re only needed when using
updateDetails which requires them for authentication.
• token - A valid Discord authentication token used to log in, String
• email - (Optional) The e-mail used for later authentication, String.
• password - (Optional) The password used for later authentication, String.
• callback - function that takes the following parameters:
– error - An error if any occurred
– token - A String containing the specified token. This is only used for compatibility with login, this
token will always be identical to the specified one.
logout(callback )
1.5. Client 13
discord.js Documentation, Release 8.2.0
destroy(callback )
Similar to logout but should be used if you’re not going to create the Client again later in your program.
• callback - function that takes the following parameter:
– error - An error if any occurred
Shortcut to sendMessage but prepends a mention to the sender of the original message to the start of your message.
• message - The Message to reply to
• content - a String Resolvable - the message you want to send
• options - object containing:
– tts - Boolean, should message be text-to-speech
• callback - function that takes the following parameters:
– error - error object if any occurred
– message - the sent Message
Wait for a response from the same user in the same channel as an existing message.
• message - The original Message
• prompt - a String Resolvable - a message you want to send to prompt the user
• options - object containing:
– tts - Boolean, should message be text-to-speech
• callback - function that takes the following parameters:
– error - error object if any occurred
– message - the sent Message
1.5. Client 15
discord.js Documentation, Release 8.2.0
deleteMessages(messages, callback )
Gets a message. This also works for messages that aren’t cached but will only work for OAuth bot accounts.
• channel - The Channel to get the message from.
• messageID - The message id to get the message object from. A String
• callback - function taking the following:
– error - error if any occurred
– message - The Message
pinMessage(message, callback )
unpinMessage(message, callback )
getPinnedMessages(channel, callback )
getBans(server, callback )
joinServer(invite, callback )
Joins a server from the given invite. This will not work for OAuth bot accounts, you must use OAuth invite URLs
instead.
• invite - an Invite Resolvable
• callback - function taking the following:
– error - error if any occurred
– server - the joined Server
1.5. Client 17
discord.js Documentation, Release 8.2.0
Creates a server
• name - String, name of the server
• region - String, region of the server, currently us-west, us-east, us-south, us-central, singapore, london,
sydney, frankfurt or amsterdam
• callback - function taking the following:
– error - error if any occurred
– server - the created Server
deleteServer(server, callback )
leaveServer(server, callback )
deleteChannel(channel, callback )
1.5. Client 19
discord.js Documentation, Release 8.2.0
getInvite(invite, callback )
getInvites(source, callback )
deleteInvite(invite, callback )
Deletes an invite
• invite - An Invite Resolvable
• callback - a function taking the following:
– error - error if any occurred
setStatusIdle()
Alias: setStatusAway
Sets the status of the Client to Idle/Away
setStatusOnline()
setPlayingGame(game, callback )
1.5. Client 21
discord.js Documentation, Release 8.2.0
– userLimit - Number, the new user limit of the channel (VoiceChannel only)
– bitrate - Number, the new bitrate (in kb/s) of the channel (VoiceChannel only)
• callback - function taking the following:
– error - error if any occurred
startTyping(channel, callback )
stopTyping(channel, callback )
Marks the client as not typing in a channel (takes a few seconds to go active).
• channel - A Channel Resolvable
• callback - function taking the following:
– error - error if any occurred
updateDetails(details, callback )
setAvatar(avatar, callback )
1.5. Client 23
discord.js Documentation, Release 8.2.0
setUsername(name, callback )
joinVoiceChannel(channel, callback )
Joins a Voice Channel to begin transmitting audio. If you have an OAuth bot account, you can connect to multiple
voice channels at once, but only one per guild.
• channel - A VoiceChannel Resolvable
• callback - function that takes the following:
– error - error if any occurred
– connection - VoiceConnection, the created Voice Connection.
leaveVoiceChannel(channel, callback )
deleteRole(role, callback )
Aliases : addUserToRole
Adds a member of a server to a role in the server
• member - A User Resolvable
• role - A Role Resolvable or an array of Role Resolvable
• callback - function that takes the following:
– error - error if any occurred
memberHasRole(member, role)
Aliases : userHasRole
Returns if a user has a role
• member - A User Resolvable
• role - A Role Resolvable or an array of Role Resolvable
1.5. Client 25
discord.js Documentation, Release 8.2.0
Aliases : removeUserFromRole
Removes a member of a server from a role in the server
• member - A User Resolvable
• role - A Role Resolvable or an array of Role Resolvable
• callback - function that takes the following:
– error - error if any occurred
{
"sendMessages" : false,
"attachFiles" : true
}
Server-mutes a member.
• user - A User Resolvable to mute
• server - A Server Resolvable to mute the user in
• callback - function taking the following:
– error - error if any occurred.
Server-unmutes a member.
• user - A User Resolvable to unmute
• server - A Server Resolvable to unmute the user in
• callback - function taking the following:
– error - error if any occurred.
Server-deafens a member.
• user - A User Resolvable to deafen
• server - A Server Resolvable to deafen the user in
• callback - function taking the following:
– error - error if any occurred.
Server-undeafens a member.
• user - A User Resolvable to undeafen
• server - A Server Resolvable to undeafen the user in
• callback - function taking the following:
– error - error if any occurred.
Set the note of a user. This will only work for user accounts.
• user - A User Resolvable to which the note is applied.
• note - String, content of the note, or null to clear.
• callback - function taking the following:
– error - error if any occurred.
getOAuthApplication(appID, callback )
1.5. Client 27
discord.js Documentation, Release 8.2.0
– data - the application data. Refer to the official Discord API documentation entry for data structure
details
1.5.4 Events
Discord.Client is an EventEmitter, so you can use .on() and .off() to add and remove events.
ready
debug
message
warn
Emitted when the client has encountered a small error that can be avoided.
messageDeleted
Emitted when a message has been deleted and the Client finds out, supplies a Message object IF available, and a
Channel object.
messageUpdated
Emitted when a message has been updated and the client finds out. Supplies two Message objects, the first being the
message before the update, the second being the new, updated message.
disconnected
error
Emitted when the client runs into a big problem, supplies an error object.
raw
Emitted when a message over WebSocket is received, it supplies one object containing the raw data from the Web-
Socket.
serverCreated
serverDeleted
serverUpdated
Emitted when a server is updated (e.g. name change). Supplies two Server objects, the first being the server before the
update, the second being the new, updated server.
channelCreated
Emitted when a channel is created, supplies a Channel object (includes PM chats as well as server channels).
channelDeleted
channelUpdated
Emitted when a channel is updated (e.g. name/topic change). Supplies two Channel objects, the first being the channel
before the update, the second being the new, updated channel.
serverRoleCreated
serverRoleDeleted
serverRoleUpdated
Emitted when a role is updated in a server, supplies two Role objects. The first is the old role, the second is the updated
role.
serverNewMember
Emitted when a user joins a server, supplies a Server object and a User object.
serverMemberRemoved
Emitted when a member is removed from a server. Supplies a Server object and a User object.
1.5. Client 29
discord.js Documentation, Release 8.2.0
serverMemberUpdated
Emitted when a member in a server is updated. Supplies a Server object and 2 User objects, the first being the new,
updated user, the second being the old one. The old user object could be null if the bot didn’t previously have the
member cached.
presence
Emitted when a user goes online/offline/idle, starts/stops playing a game, or changes their username/avatar/similar.
Supplies 2 User objects, the first being the old user, the second being the new, updated user.
userTypingStarted
Emitted when a user starts typing in a channel. Supplies two parameters, a User object and a Channel object.
userTypingStopped
Emitted when a user stop typing in a channel. Supplies two parameters, a User object and a Channel object.
userBanned
Emitted when a user is banned from a server. Supplies two parameters, a User object and a Server object.
userUnbanned
Emitted when a user is unbanned from a server. Supplies two parameters, a User object and a Server object.
noteUpdated
Emitted when a note is updated. Supplies a User object (containing the updated note) and the old note.
voiceJoin
Emitted when a user joins a voice channel, supplies a VoiceChannel and a User.
voiceSwitch
Emitted when a user switches voice channels, supplies the old VoiceChannel, the new VoiceChannel, and a User.
voiceLeave
Emitted when a user leaves a voice channel, supplies a VoiceChannel and a User.
voiceStateUpdate
Emitted when a user mutes/deafens, supplies a VoiceChannel, User, an object containing the old
mute/selfMute/deaf/selfDeaf properties, and an object containing the new mute/selfMute/deaf/selfDeaf properties.
voiceSpeaking
Emitted when a user starts or stops speaking, supplies a VoiceChannel, and User. The speaking property under the
supplied User object can be used to determine whether the user started or stopped speaking.
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.6 Server
extends Equality
Stores information about a Discord Server.
1.6.1 Attributes
client
region
name
id
members
channels
roles
1.6. Server 31
discord.js Documentation, Release 8.2.0
icon
afkTimeout
Number, the AFK timeout in seconds before a user is classed as AFK. If there isn’t an AFK timeout, this will be null.
afkChannel
The channel where AFK users are moved to, ServerChannel object. If one isn’t set, this will be null.
defaultChannel
owner
iconURL
The URL of the Server’s icon. If the server doesn’t have an icon, this will be null.
createdAt
1.6.2 Functions
rolesOfUser(user)
usersWithRole(role)
Aliases: membersWithRole
Returns an array of users that have the specified role.
detailsOfUser(user)
{
joinedAt: 1449339323747,
roles: [],
mute: false,
selfMute: false,
deaf: false,
selfDeaf: false,
nick: 'Nickname'
}
leave()
Shortcut of client.leaveServer(server)
Aliases delete
See client.leaveServer
createInvite(options, callback )
createRole(data, callback )
getBans(callback )
1.6. Server 33
discord.js Documentation, Release 8.2.0
unbanMember(user, callback )
kickMember(user, callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.7 User
extends Equality
Stores information about users.
1.7.1 Attributes
client
username
_Alias_ : name
String, username of the User.
discriminator
Integer from 0-9999, don’t use this to identify users. Used to separate the user from the 9998 others that may have the
same username. Made redundant by user.id.
id
String (do not parse to an Integer, will become inaccurate). The ID of a user, never changes.
avatar
String, the ID/hash of a user’s avatar. To get a path to their avatar, see user.avatarURL.
status
game
The game object of a user. null if not playing a game, otherwise Object containing the following values:
{
name : 'Game Name' //Name of game user is playing
}
typing
{
since : 1448038288519, //timestamp of when
channel : <Channel Object> // channel they are typing in.
}
avatarURL
A valid URL to the user’s avatar if they have one, otherwise null.
bot
A boolean that represents if the user is an official OAuth bot account or not.
voiceChannel
The VoiceChannel the user is connected to. If they aren’t in any voice channels, this will be null.
createdAt
note
1.7. User 35
discord.js Documentation, Release 8.2.0
speaking
A boolean that represents whether or not the user is speaking in a voice channel, default is false.
1.7.2 Functions
mention()
Returns a valid string that can be sent in a message to mention the user. By default, user.toString() does this
so by adding a user object to a string, e.g. user + "", their mention code will be retrieved.
sendTTSMessage(content, callback )
startTyping(callback )
stopTyping(callback )
addTo(role, callback )
removeFrom(role, callback )
getMessage(messageID, callback )
hasRole(role)
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.8 Message
extends Equality
A Message object is used to represent the data of a message.
1.8.1 Attributes
channel
The channel the message was sent in, either a TextChannel or PMChannel.
server
The Server the message was sent in. Will be undefined if the message was sent in a PMChannel.
client
1.8. Message 37
discord.js Documentation, Release 8.2.0
attachments
tts
embeds
timestamp
everyoneMentioned
id
editedTimestamp
Timestamp on when the message was last edited, Number. Potentially null.
author
Alias: sender
The User that sent the message.
content
cleanContent
String, content of the message with valid user mentions (<@123>) replaced with “@username”.
mentions
pinned
1.8.2 Functions
isMentioned(user)
toString()
delete(options, callback )
replyTTS(content, callback )
pin(callback )
1.8. Message 39
discord.js Documentation, Release 8.2.0
unpin(callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.9 Invite
1.9.1 Attributes
maxAge
Number, how long (in seconds) the invite has since creation before expiring.
code
server
channel
revoked
createdAt
temporary
uses
maxUses
inviter
xkcd
Boolean, whether the invite is intended to be easy to read and remember by a human.
1.9.2 Functions
toString()
delete(callback )
join(callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.10 VoiceConnection
discordv8 currently supports sending audio data over Discord voice chat. A voice connection can be initiated using
client.joinVoiceChannel and then later accessed again using the client.voiceConnection property. You can play some-
thing using the playXYZ methods and then later stop the playback and listen for events that tell you about the playback
status.
Note that discordv8 does not support receiving data from voice yet, only sending.
1.10. VoiceConnection 41
discord.js Documentation, Release 8.2.0
1.10.1 Attributes
voiceChannel
client
token
server
encoder
playingIntent
playing
paused
streamTime
The amount of time the current track has been playing for, in milliseconds
1.10.2 Functions
Plays a file to the voice channel. The file can be in practically any format; if you’re looking for a list, look here: Format
list. In addition to a file path local to your computer, it can also accept a URL, however this is not recommended as
the entire content of the URL will be read before any playback starts. This can cause delays from seconds to minutes
- you can use playRawStream with a Stream obtained from the URL instead.
The options object can be used to control playback properties, currently, it allows setting the seek (in seconds) using
the seek property, and the volume using the volume property, which can be in any of the following formats:
• A number representing the linear change in volume; 1 is equal to no change, 0 is completely silent, 0.5 is half
the regular volume and 2 is double the regular volume.
• A string representing the linear change in volume, if this is more convenient for you.
• A string representing decibel gain, where “0dB” is no change, “-3dB” is half the volume (in linear units),
“+6dB” is four times the volume (in linear units) and so on.
It is recommended to change the volume, because the default of 1 is usually too loud. (A reasonable setting is 0.25 or
“-6dB”).
The callback will be called immediately after playback has started, it will have an error object and the stream intent
as its parameters. The callback will only receive an error if the encoding fails, for playback errors, you can bind a
function to the error event of the intent. The intent supports the following events:
• The time event is emitted every packet (20 milliseconds) and has the current playback time in milliseconds as
its only parameter. The playback time can also be checked at any time using the streamTime attribute.
• The end event is emitted once playback ends. Depending on various factors, it may be emitted a couple seconds
earlier than the actual stream ending, you may have to add an offset if necessary.
• The error event is emitted if an error happens during playback, such as failing to send a packet.
The intent can later be accessed again using the playingIntent property. If you prefer _Promises over callbacks, this
method will return a promise you can use in the same way as the callback.
This method is used in much the same way as playFile, except it plays data back from a stream containing audio data
instead of a file or URL.
This method can be used to play data obtained from an arbitrary call to ffmpeg. Note that the array of options given as
the parameter will still be concatenated with the following options so it can be used with Discord:
-loglevel 0
-f s16le
-ar 48000
-ac 2
pipe:1
1.10. VoiceConnection 43
discord.js Documentation, Release 8.2.0
setSpeaking(value)
Sets whether or not the user is speaking (green circle around user on the official client). discordv8 does this automati-
cally when playing something, but you may want to spoof it or manually disable it.
• value - true or false: whether or not you want the bot to show as speaking
setVolume(volume)
Sets the current volume of the connecion. 1.0 is normal, 0.5 is half as loud, 2.0 is twice as loud.
getVolume()
Returns the current volume. 1.0 is normal, 0.5 is half as loud, 2.0 is twice as loud.
pause()
resume()
stopPlaying()
Stops the current playback immediately. After this method has finished, it is safe to play something else.
destroy()
Disconnects from the voice server and destroys all network connection. It’s impossible to play anything on this
connection afterwards, you will have to re-initiate a connection using client.joinVoiceChannel. This method also calls
stopPlaying internally, you don’t have to do that yourself.
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.11 Channel
extends Equality
The Channel class is the base class for all types of channel.
1.11.1 Attributes
id
client
isPrivate
createdAt
1.11.2 Functions
delete()
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.12 PMChannel
extends Channel
A PMChannel is a Private/Direct channel between the Client and another user.
1.12.1 Attributes
messages
recipient
1.12. PMChannel 45
discord.js Documentation, Release 8.2.0
lastMessage
The last Message sent in the channel, may be null if no messages have been sent during the time the bound Client has
been online.
1.12.2 Functions
toString()
sendTTSMessage(content, callback )
startTyping(callback )
stopTyping(callback )
getMessage(messageID, callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.13 ServerChannel
extends Channel
A ServerChannel is a Channel that belongs to a Server.
1.13.1 Attributes
name
type
position
permissionOverwrites
server
1.13.2 Functions
permissionsOf(userOrRole)
Aliases: permsOf
Returns a ChannelPermissions object of a user or role’s permissions in that channel.
1.13. ServerChannel 47
discord.js Documentation, Release 8.2.0
mention()
Returns a string that can be used in discord messages to mention a channel. serverChannel.toString() defaults to this.
update(data, callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.14 TextChannel
extends ServerChannel
A text channel of a server.
1.14.1 Attributes
topic
lastMessage
Last Message sent in the channel. May be null if no messages sent whilst the Client was online.
messages
1.14.2 Functions
setTopic(topic, callback )
sendTTSMessage(content, callback )
startTyping(callback )
stopTyping(callback )
getMessage(messageID, callback )
1.14. TextChannel 49
discord.js Documentation, Release 8.2.0
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.15 VoiceChannel
extends ServerChannel
A voice channel of a server. Currently, the voice channel class has no differences to the ServerChannel class.
1.15.1 Attributes
members
userLimit
The maximum amount of users that can connect to the voice channel. If it’s 0, there is no limit
bitrate
1.15.2 Functions
setUserLimit(limit, callback )
setBitrate(kbitrate, callback )
join(callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
In discord.js, you can handle permissions in two ways. The preferred way is to just use the string name of the
permission, alternatively you can use Discord.Constants.Permissions["permission name"].
{
// general
administrator,
createInstantInvite,
kickMembers,
banMembers,
manageRoles,
managePermissions,
manageChannels,
manageChannel,
manageServer,
changeNickname,
manageNicknames,
// text
readMessages,
sendMessages,
sendTTSMessages,
manageMessages,
embedLinks,
attachFiles,
readMessageHistory,
mentionEveryone,
// voice
voiceConnect,
voiceSpeak,
voiceMuteMembers,
voiceDeafenMembers,
voiceMoveMembers,
voiceUseVAD
};
The preferred way of using permissions in discordv8 is to just use the name. E.g:
role.hasPermission("voiceUseVAD")
1.16.3 Alternative
You can also go the long way round and use the numerical permission like so:
role.hasPermission( Discord.Constants.Permissions.voiceUseVAD )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.17 Role
1.17.1 Attributes
position
name
managed
Boolean, whether Discord has created the role itself. Currently only used for Twitch integration.
id
hoist
Boolean, whether the role should be displayed as a separate category in the users section.
color
server
client
createdAt
1.17.2 Functions
serialise()
Aliases: serialize
Makes an object with the permission names found in Permission Constants and a boolean value for them.
hasPermission(permission)
colorAsHex()
mention()
Returns a valid string that can be sent in a message to mention the role. By default, role.toString() does this so
by adding a role object to a string, e.g. role + "", their mention code will be retrieved. If the role isn’t mentionable,
its name gets returned.
delete()
Shortcut of client.deleteRole(role)
See client.deleteRole
update(data)
addMember(member, callback )
1.17. Role 53
discord.js Documentation, Release 8.2.0
removeMember(member, callback )
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.18 PermissionOverwrite
PermissionOverwrite is used to represent data about permission overwrites for roles or users in channels.
1.18.1 Attributes
id
String, the ID of the PermissionOverwrite. If overwrite.type is role, this is the role’s ID. Otherwise, it is a
User overwrite.
type
allowed
Returns the permissions explicitly allowed by the overwrite. An Array of Strings, which are names of permissions.
More can be found at Permission Constants
denied
Returns the permissions explicitly denied by the overwrite. An Array of Strings, which are names of permissions.
More can be found at Permission Constants
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.19 ChannelPermissions
ChannelPermissions is used to represent the final permissions of a user in a channel, to see exactly what they are and
aren’t allowed to do.
Examples:
1.19.1 Functions
serialize()
Aliases: serialise
Returns an object containing permission names and values. E.g:
{
createInstantInvite : true,
kickMembers : false
}
hasPermission(permission)
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.20 Cache
extends Array
A Cache object extends an Array (so it can be used like a regular array) but introduces helper functions to make it
more useful when developing with discordv8. Unlike a regular array, it doesn’t care about the instance or prototype of
an object, it works purely on properties.
Examples:
client.users.get("id", 11238414);
client.channels.getAll("name", "general");
1.19. ChannelPermissions 55
discord.js Documentation, Release 8.2.0
1.20.1 Functions
get(key, value)
Returns a contained object where object[key] == value. Also works if value is a regex or a function. Returns
the first object found that matches the criteria.
get(value)
Returns a contained object where object["id"] == value. Shorthand for get("id", value). Returns
null if ID is not found.
getAll(key, value)
Similar to cache.get(key, value), but returns a Cache of any objects that meet the criteria.
has(key, value)
Returns true if there is an object that meets the condition object[key] == value in the cache
add(data)
Adds an object to the Cache as long as all the other objects in the cache don’t have the same ID as it.
update(old, data)
Updates an old object in the Cache (if it exists) with the new one.
remove(data)
random()
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.21 Equality
The Equality class is used to see if two objects are equal, based on object_1.id === object_2.id.
If any class in Discord extends equality, it means you should never the default equality operands (== & ===) as
they could potentially be different instances and therefore appear not to be equal. Instead, use equalityObject.
equals() as shown below.
object1.equals(object2); // GOOD X
1.21.1 Functions
equals(object)
Danger: This documentation is for the discord.js 8.2 branch called discordv8 maintained by macdja38. You’re
probably looking for documentation on version 9 or higher, which is available on the other docs site.
1.22 Resolvables
In discordv8, the aim is to allow the end developer to have freedom in what sort of data types they supply. References
to any sort of resolvable basically mean what types of data you can provide. The different resolvables are shown
before:
1.22. Resolvables 57
discord.js Documentation, Release 8.2.0
• String of Server ID
1.22. Resolvables 59