{"meta":{"generator":"0.9.0","format":20,"date":1621671456131},"custom":{"general":{"name":"General","files":{"welcome":{"name":"Welcome","type":"md","content":"
\n\n# Welcome!\n\nWelcome to the discord.js v12 documentation.\n\n## About\n\ndiscord.js is a powerful [Node.js](https://nodejs.org) module that allows you to easily interact with the\n[Discord API](https://discord.com/developers/docs/intro).\n\n- Object-oriented\n- Predictable abstractions\n- Performant\n- 100% coverage of the Discord API\n\n## Installation\n\n**Node.js 12.0.0 or newer is required.** \nIgnore any warnings about unmet peer dependencies, as they're all optional.\n\nWithout voice support: `npm install discord.js` \nWith voice support ([@discordjs/opus](https://www.npmjs.com/package/@discordjs/opus)): `npm install discord.js @discordjs/opus` \nWith voice support ([opusscript](https://www.npmjs.com/package/opusscript)): `npm install discord.js opusscript`\n\n### Audio engines\n\nThe preferred audio engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus.\nUsing opusscript is only recommended for development environments where @discordjs/opus is tough to get working.\nFor production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.\n\n### Optional packages\n\n- [zlib-sync](https://www.npmjs.com/package/zlib-sync) for WebSocket data compression and inflation (`npm install zlib-sync`)\n- [erlpack](https://github.com/discord/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install discord/erlpack`)\n- One of the following packages can be installed for faster voice packet encryption and decryption:\n - [sodium](https://www.npmjs.com/package/sodium) (`npm install sodium`)\n - [libsodium.js](https://www.npmjs.com/package/libsodium-wrappers) (`npm install libsodium-wrappers`)\n- [bufferutil](https://www.npmjs.com/package/bufferutil) for a much faster WebSocket connection (`npm install bufferutil`)\n- [utf-8-validate](https://www.npmjs.com/package/utf-8-validate) in combination with `bufferutil` for much faster WebSocket processing (`npm install utf-8-validate`)\n\n## Example usage\n\n```js\nconst Discord = require('discord.js');\nconst client = new Discord.Client();\n\nclient.on('ready', () => {\n console.log(`Logged in as ${client.user.tag}!`);\n});\n\nclient.on('message', msg => {\n if (msg.content === 'ping') {\n msg.reply('pong');\n }\n});\n\nclient.login('token');\n```\n\n## Links\n\n- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))\n- [Documentation](https://discord.js.org/#/docs/main/master/general/welcome)\n- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide)) - this is still for stable \n See also the WIP [Update Guide](https://discordjs.guide/additional-info/changes-in-v12.html) also including updated and removed items in the library.\n- [Discord.js Discord server](https://discord.gg/bRCvFy9)\n- [Discord API Discord server](https://discord.gg/discord-api)\n- [GitHub](https://github.com/discordjs/discord.js)\n- [NPM](https://www.npmjs.com/package/discord.js)\n- [Related libraries](https://discordapi.com/unofficial/libs.html)\n\n### Extensions\n\n- [RPC](https://www.npmjs.com/package/discord-rpc) ([source](https://github.com/discordjs/RPC))\n\n## Contributing\n\nBefore creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the\n[documentation](https://discord.js.org/#/docs). \nSee [the contribution guide](https://github.com/discordjs/discord.js/blob/master/.github/CONTRIBUTING.md) if you'd like to submit a PR.\n\n## Help\n\nIf you don't understand something in the documentation, you are experiencing problems, or you just need a gentle\nnudge in the right direction, please don't hesitate to join our official [Discord.js Server](https://discord.gg/bRCvFy9).\n","path":"docs/general/welcome.md"},"updating":{"name":"Updating your code","type":"md","content":"# Version 12.0.0\n\nv12.0.0 contains many new and improved features, optimisations, and bug fixes.\nSee [the changelog](https://github.com/discordjs/discord.js/releases/tag/12.0.0) for a full list of changes.\nYou can also visit [the guide](https://discordjs.guide/additional-info/changes-in-v12.html) for help with updating your v11 code to v12.\n\n# Version 11.1.0\n\nv11.1.0 features improved voice and gateway stability, as well as support for new features such as audit logs and searching for messages.\nSee [the changelog](https://github.com/discordjs/discord.js/releases/tag/11.1.0) for a full list of changes, including\ninformation about deprecations.\n\n# Version 11\n\nVersion 11 contains loads of new and improved features, optimisations, and bug fixes.\nSee [the changelog](https://github.com/discordjs/discord.js/releases/tag/11.0.0) for a full list of changes.\n\n## Significant additions\n\n- Message Reactions and Embeds (rich text)\n- Support for uws and erlpack for better performance\n- OAuthApplication support\n- Web distributions\n\n## Breaking changes\n\n### Client.login() no longer supports logging in with email + password\n\nLogging in with an email and password has always been heavily discouraged since the advent of proper token support, but in v11 we have made the decision to completely remove the functionality, since Hammer & Chisel have [officially stated](https://github.com/hammerandchisel/discord-api-docs/issues/69#issuecomment-223886862) it simply shouldn't be done.\n\nUser accounts can still log in with tokens just like bot accounts. To obtain the token for a user account, you can log in to Discord with that account, and use Ctrl + Shift + I to open the developer tools. In the console tab, evaluating `localStorage.token` will give you the token for that account.\n\n### ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts\n\nSince you can no longer log in with email and password, you must provide the current account password to the `setEmail()`, `setPassword()`, and `setUsername()` methods for user accounts (self-bots).\n\n### Removed TextBasedChannel.sendTTSMessage()\n\nThis method was deemed to be an entirely pointless shortcut that virtually nobody even used.\nThe same results can be achieved by passing options to `send()` or `sendMessage()`.\n\nExample:\n\n```js\nchannel.send('Hi there', { tts: true });\n```\n\n### Using Collection.find()/exists() with IDs will throw an error\n\nThis is simply to help prevent a common mistake that is made frequently.\nTo find something or check its existence using an ID, you should use `.get()` and `.has()` which are part of the [ES6 Map class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map), which Collection is an extension of.\n\n# Version 10\n\nVersion 10's non-BC changes focus on cleaning up some inconsistencies that exist in previous versions.\nUpgrading from v9 should be quick and painless.\n\n## Client options\n\nAll client options have been converted to camelCase rather than snake_case, and `max_message_cache` was renamed to `messageCacheMaxSize`.\n\nv9 code example:\n\n```js\nconst client = new Discord.Client({\n disable_everyone: true,\n max_message_cache: 500,\n message_cache_lifetime: 120,\n message_sweep_interval: 60,\n});\n```\n\nv10 code example:\n\n```js\nconst client = new Discord.Client({\n disableEveryone: true,\n messageCacheMaxSize: 500,\n messageCacheLifetime: 120,\n messageSweepInterval: 60,\n});\n```\n\n## Presences\n\nPresences have been completely restructured.\nPrevious versions of discord.js assumed that users had the same presence amongst all guilds - with the introduction of sharding, however, this is no longer the case.\n\nv9 discord.js code may look something like this:\n\n```js\nUser.status; // the status of the user\nUser.game; // the game that the user is playing\nClientUser.setStatus(status, game, url); // set the new status for the user\n```\n\nv10 moves presences to GuildMember instances. For the sake of simplicity, though, User classes also expose presences.\nWhen accessing a presence on a User object, it simply finds the first GuildMember for the user, and uses its presence.\nAdditionally, the introduction of the Presence class keeps all of the presence data organised.\n\n**It is strongly recommended that you use a GuildMember's presence where available, rather than a User.\nA user may have an entirely different presence between two different guilds.**\n\nv10 code:\n\n```js\nMemberOrUser.presence.status; // the status of the member or user\nMemberOrUser.presence.game; // the game that the member or user is playing\nClientUser.setStatus(status); // online, idle, dnd, offline\nClientUser.setGame(game, streamingURL); // a game\nClientUser.setPresence(fullPresence); // status and game combined\n```\n\n## Voice\n\nVoice has been rewritten internally, but in a backwards-compatible manner.\nThere is only one breaking change here; the `disconnected` event was renamed to `disconnect`.\nSeveral more events have been made available to a VoiceConnection, so see the documentation.\n\n## Events\n\nMany events have been renamed or had their arguments change.\n\n### Client events\n\n| Version 9 | Version 10 |\n| ---------------------------------------------- | --------------------------------------- |\n| guildMemberAdd(guild, member) | guildMemberAdd(member) |\n| guildMemberAvailable(guild, member) | guildMemberAvailable(member) |\n| guildMemberRemove(guild, member) | guildMemberRemove(member) |\n| guildMembersChunk(guild, members) | guildMembersChunk(members) |\n| guildMemberUpdate(guild, oldMember, newMember) | guildMemberUpdate(oldMember, newMember) |\n| guildRoleCreate(guild, role) | roleCreate(role) |\n| guildRoleDelete(guild, role) | roleDelete(role) |\n| guildRoleUpdate(guild, oldRole, newRole) | roleUpdate(oldRole, newRole) |\n\nThe guild parameter that has been dropped from the guild-related events can still be derived using `member.guild` or `role.guild`.\n\n### VoiceConnection events\n\n| Version 9 | Version 10 |\n| ------------ | ---------- |\n| disconnected | disconnect |\n\n## Dates and timestamps\n\nAll dates/timestamps on the structures have been refactored to have a consistent naming scheme and availability.\nAll of them are named similarly to this: \n**Date:** `Message.createdAt` \n**Timestamp:** `Message.createdTimestamp` \nSee the docs for each structure to see which date/timestamps are available on them.\n\n# Version 9\n\nThe version 9 (v9) rewrite takes a much more object-oriented approach than previous versions,\nwhich allows your code to be much more readable and manageable.\nIt's been rebuilt from the ground up and should be much more stable, fixing caching issues that affected\nolder versions. It also has support for newer Discord Features, such as emojis.\n\nVersion 9, while containing a sizable number of breaking changes, does not require much change in your code's logic -\nmost of the concepts are still the same, but loads of functions have been moved around.\nThe vast majority of methods you're used to using have been moved out of the Client class,\ninto other more relevant classes where they belong.\nBecause of this, you will need to convert most of your calls over to the new methods.\n\nHere are a few examples of methods that have changed:\n\n- `Client.sendMessage(channel, message)` ==> `TextChannel.sendMessage(message)`\n - `Client.sendMessage(user, message)` ==> `User.sendMessage(message)`\n- `Client.updateMessage(message, \"New content\")` ==> `Message.edit(\"New Content\")`\n- `Client.getChannelLogs(channel, limit)` ==> `TextChannel.fetchMessages({options})`\n- `Server.detailsOfUser(User)` ==> `Server.members.get(User).properties` (retrieving a member gives a GuildMember object)\n- `Client.joinVoiceChannel(voicechannel)` => `VoiceChannel.join()`\n\nA couple more important details:\n\n- `Client.loginWithToken(\"token\")` ==> `client.login(\"token\")`\n- `Client.servers.length` ==> `client.guilds.size` (all instances of `server` are now `guild`)\n\n## No more callbacks!\n\nVersion 9 eschews callbacks in favour of Promises. This means all code relying on callbacks must be changed. \nFor example, the following code:\n\n```js\nclient.getChannelLogs(channel, 100, function(messages) {\n console.log(`${messages.length} messages found`);\n});\n```\n\n```js\nchannel.fetchMessages({ limit: 100 }).then(messages => {\n console.log(`${messages.size} messages found`);\n});\n```\n","path":"docs/general/updating.md"},"faq":{"name":"FAQ","type":"md","content":"# Frequently Asked Questions\n\nThese questions are some of the most frequently asked.\n\n## No matter what, I get `SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode`‽\n\nUpdate to Node.js 12.0.0 or newer.\n\n## How do I get voice working?\n\n- Install FFMPEG.\n- Install either the `@discordjs/opus` package or the `opusscript` package.\n @discordjs/opus is greatly preferred, due to it having significantly better performance.\n\n## How do I install FFMPEG?\n\n- **npm:** `npm install ffmpeg-static`\n- **Ubuntu 16.04:** `sudo apt install ffmpeg`\n- **Ubuntu 14.04:** `sudo apt-get install libav-tools`\n- **Windows:** `npm install ffmpeg-static` or see the [FFMPEG section of AoDude's guide](https://github.com/bdistin/OhGodMusicBot/blob/master/README.md#download-ffmpeg).\n\n## How do I set up @discordjs/opus?\n\n- **Ubuntu:** Simply run `npm install @discordjs/opus`, and it's done. Congrats!\n- **Windows:** Run `npm install --global --production windows-build-tools` in an admin command prompt or PowerShell.\n Then, running `npm install @discordjs/opus` in your bot's directory should successfully build it. Woo!\n\nOther questions can be found at the [official Discord.js guide](https://discordjs.guide/popular-topics/common-questions.html)\nIf you have issues not listed here or on the guide, feel free to ask in the [official Discord.js server](https://discord.gg/bRCvFy9).\nAlways make sure to read the [documentation](https://discord.js.org/#/docs/main/stable/general/welcome).\n","path":"docs/general/faq.md"}}},"topics":{"name":"Topics","files":{"voice":{"name":"Voice","type":"md","content":"# Introduction to Voice\n\nVoice in discord.js can be used for many things, such as music bots, recording or relaying audio.\n\nIn discord.js, you can use voice by connecting to a `VoiceChannel` to obtain a `VoiceConnection`, where you can start streaming and receiving audio.\n\nTo get started, make sure you have:\n\n- FFmpeg - `npm install ffmpeg-static`\n- an opus encoder, choose one from below:\n - `npm install @discordjs/opus` (better performance)\n - `npm install opusscript`\n- a good network connection\n\nThe preferred opus engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus.\nUsing opusscript is only recommended for development environments where @discordjs/opus is tough to get working.\nFor production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.\n\n## Joining a voice channel\n\nThe example below reacts to a message and joins the sender's voice channel, catching any errors. This is important\nas it allows us to obtain a `VoiceConnection` that we can start to stream audio with.\n\n```js\nconst Discord = require('discord.js');\nconst client = new Discord.Client();\n\nclient.login('token here');\n\nclient.on('message', async message => {\n // Voice only works in guilds, if the message does not come from a guild,\n // we ignore it\n if (!message.guild) return;\n\n if (message.content === '/join') {\n // Only try to join the sender's voice channel if they are in one themselves\n if (message.member.voice.channel) {\n const connection = await message.member.voice.channel.join();\n } else {\n message.reply('You need to join a voice channel first!');\n }\n }\n});\n```\n\n## Streaming to a Voice Channel\n\nIn the previous example, we looked at how to join a voice channel in order to obtain a `VoiceConnection`. Now that we\nhave obtained a voice connection, we can start streaming audio to it.\n\n### Introduction to playing on voice connections\n\nThe most basic example of playing audio over a connection would be playing a local file:\n\n```js\nconst dispatcher = connection.play('/home/discord/audio.mp3');\n```\n\nThe `dispatcher` in this case is a `StreamDispatcher` - here you can control the volume and playback of the stream:\n\n```js\ndispatcher.pause();\ndispatcher.resume();\n\ndispatcher.setVolume(0.5); // half the volume\n\ndispatcher.on('finish', () => {\n console.log('Finished playing!');\n});\n\ndispatcher.destroy(); // end the stream\n```\n\nWe can also pass in options when we first play the stream:\n\n```js\nconst dispatcher = connection.play('/home/discord/audio.mp3', {\n volume: 0.5,\n});\n```\n\n### What can I play?\n\nDiscord.js allows you to play a lot of things:\n\n```js\n// ReadableStreams, in this example YouTube audio\nconst ytdl = require('ytdl-core');\nconnection.play(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { filter: 'audioonly' }));\n\n// Files on the internet\nconnection.play('http://www.sample-videos.com/audio/mp3/wave.mp3');\n\n// Local files\nconnection.play('/home/discord/audio.mp3');\n```\n\nNew to v12 is the ability to play OggOpus and WebmOpus streams with much better performance by skipping out Ffmpeg. Note this comes at the cost of no longer having volume control over the stream:\n\n```js\nconnection.play(fs.createReadStream('./media.webm'), {\n type: 'webm/opus',\n});\n\nconnection.play(fs.createReadStream('./media.ogg'), {\n type: 'ogg/opus',\n});\n```\n\nMake sure to consult the documentation for a full list of what you can play - there's too much to cover here!\n\n## Voice Broadcasts\n\nA voice broadcast is very useful for \"radio\" bots, that play the same audio across multiple channels. It means audio is only transcoded once, and is much better on performance.\n\n```js\nconst broadcast = client.voice.createBroadcast();\n\nbroadcast.on('subscribe', dispatcher => {\n console.log('New broadcast subscriber!');\n});\n\nbroadcast.on('unsubscribe', dispatcher => {\n console.log('Channel unsubscribed from broadcast :(');\n});\n```\n\n`broadcast` is an instance of `VoiceBroadcast`, which has the same `play` method you are used to with regular VoiceConnections:\n\n```js\nconst dispatcher = broadcast.play('./audio.mp3');\n\nconnection.play(broadcast);\n```\n\nIt's important to note that the `dispatcher` stored above is a `BroadcastDispatcher` - it controls all the dispatcher subscribed to the broadcast, e.g. setting the volume of this dispatcher affects the volume of all subscribers.\n\n## Voice Receive\n\ncoming soon™\n","path":"docs/topics/voice.md"},"web":{"name":"Web builds","type":"md","content":"# Web builds\n\nIn addition to your usual Node applications, discord.js has special distributions available that are capable of running in web browsers.\nThis is useful for client-side web apps that need to interact with the Discord API.\n[Webpack 3](https://webpack.js.org/) is used to build these.\n\n## Restrictions\n\n- Any voice-related functionality is unavailable, as there is currently no audio encoding/decoding capabilities without external native libraries,\n which web browsers do not support.\n- The ShardingManager cannot be used, since it relies on being able to spawn child processes for shards.\n- None of the native optional packages are usable.\n\n### Require Library\n\nIf you are making your own webpack project, you can require `discord.js/browser` wherever you need to use discord.js, like so:\n\n```js\nconst Discord = require('discord.js/browser');\n// do something with Discord like you normally would\n```\n\n### Webpack File\n\nYou can obtain your desired version of discord.js' web build from the [webpack branch](https://github.com/discordjs/discord.js/tree/webpack) of the GitHub repository.\nThere is a file for each branch and version of the library, and the ones ending in `.min.js` are minified to substantially reduce the size of the source code.\n\nInclude the file on the page just as you would any other JS library, like so:\n\n```html\n\n```\n\nRather than importing discord.js with `require('discord.js')`, the entire `Discord` object is available as a global (on the `window`) object.\nThe usage of the API isn't any different from using it in Node.js.\n\n#### Example\n\n```html\n\n\n```\n","path":"docs/topics/web.md"},"partials":{"name":"Partials","type":"md","content":"# Partials\n\nPartials allow you to receive events that contain uncached instances, providing structures that contain very minimal\ndata. For example, if you were to receive a `messageDelete` event with an uncached message, normally Discord.js would\ndiscard the event. With partials, you're able to receive the event, with a Message object that contains just an ID.\n\n## Opting in\n\nPartials are opt-in, and you can enable them in the Client options by specifying [PartialTypes](/#/docs/main/master/typedef/PartialType):\n\n```js\n// Accept partial messages, DM channels, and reactions when emitting events\nnew Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });\n```\n\n## Usage & warnings\n\n