chore: consistency/prettier (#3852)

* chore: consistency/prettier

* chore: rebase

* chore: rebase

* chore: include typings

* fix: include typings file in prettier lint-staged
This commit is contained in:
Crawl
2020-02-29 14:35:57 +01:00
committed by GitHub
parent 6650d50a56
commit c065156a88
127 changed files with 5198 additions and 4513 deletions

View File

@@ -36,7 +36,7 @@ client.on('messageDelete', message => {
if (!message.partial) {
console.log(`It had content: "${message.content}"`);
}
})
});
// You can also try to upgrade partials to full instances:
client.on('messageReactionAdd', async (reaction, user) => {

View File

@@ -1,20 +1,23 @@
# Introduction to Voice
Voice in discord.js can be used for many things, such as music bots, recording or relaying audio.
In discord.js, you can use voice by connecting to a `VoiceChannel` to obtain a `VoiceConnection`, where you can start streaming and receiving audio.
To get started, make sure you have:
* FFmpeg - `npm install ffmpeg-static`
* an opus encoder, choose one from below:
* `npm install @discordjs/opus` (better performance)
* `npm install opusscript`
* a good network connection
- FFmpeg - `npm install ffmpeg-static`
- an opus encoder, choose one from below:
- `npm install @discordjs/opus` (better performance)
- `npm install opusscript`
- a good network connection
The preferred opus engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus.
Using opusscript is only recommended for development environments where @discordjs/opus is tough to get working.
For production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.
## Joining a voice channel
The example below reacts to a message and joins the sender's voice channel, catching any errors. This is important
as it allows us to obtain a `VoiceConnection` that we can start to stream audio with.
@@ -41,10 +44,12 @@ client.on('message', async message => {
```
## Streaming to a Voice Channel
In the previous example, we looked at how to join a voice channel in order to obtain a `VoiceConnection`. Now that we
have obtained a voice connection, we can start streaming audio to it.
### Introduction to playing on voice connections
The most basic example of playing audio over a connection would be playing a local file:
```js
@@ -70,7 +75,7 @@ We can also pass in options when we first play the stream:
```js
const dispatcher = connection.play('/home/discord/audio.mp3', {
volume: 0.5
volume: 0.5,
});
```
@@ -81,9 +86,7 @@ Discord.js allows you to play a lot of things:
```js
// ReadableStreams, in this example YouTube audio
const ytdl = require('ytdl-core');
connection.play(ytdl(
'https://www.youtube.com/watch?v=ZlAU_w7-Xp8',
{ filter: 'audioonly' }));
connection.play(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { filter: 'audioonly' }));
// Files on the internet
connection.play('http://www.sample-videos.com/audio/mp3/wave.mp3');
@@ -96,11 +99,11 @@ New to v12 is the ability to play OggOpus and WebmOpus streams with much better
```js
connection.play(fs.createReadStream('./media.webm'), {
type: 'webm/opus'
type: 'webm/opus',
});
connection.play(fs.createReadStream('./media.ogg'), {
type: 'ogg/opus'
type: 'ogg/opus',
});
```
@@ -119,7 +122,7 @@ broadcast.on('subscribe', dispatcher => {
broadcast.on('unsubscribe', dispatcher => {
console.log('Channel unsubscribed from broadcast :(');
})
});
```
`broadcast` is an instance of `VoiceBroadcast`, which has the same `play` method you are used to with regular VoiceConnections:
@@ -133,4 +136,5 @@ connection.play(broadcast);
It'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.
## Voice Receive
coming soon™

View File

@@ -1,26 +1,32 @@
# Web builds
In addition to your usual Node applications, discord.js has special distributions available that are capable of running in web browsers.
This is useful for client-side web apps that need to interact with the Discord API.
[Webpack 3](https://webpack.js.org/) is used to build these.
## Restrictions
- Any voice-related functionality is unavailable, as there is currently no audio encoding/decoding capabilities without external native libraries,
which web browsers do not support.
- The ShardingManager cannot be used, since it relies on being able to spawn child processes for shards.
- None of the native optional packages are usable.
### Require Library
If you are making your own webpack project, you can require `discord.js/browser` wherever you need to use discord.js, like so:
```js
const Discord = require('discord.js/browser');
// do something with Discord like you normally would
```
### Webpack File
You 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.
There 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.
Include the file on the page just as you would any other JS library, like so:
```html
<script type="text/javascript" src="discord.VERSION.min.js"></script>
```
@@ -29,6 +35,7 @@ Rather than importing discord.js with `require('discord.js')`, the entire `Disco
The usage of the API isn't any different from using it in Node.js.
#### Example
```html
<script type="text/javascript" src="discord.11.1.0.min.js"></script>
<script type="text/javascript">