Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 51177be

Browse files
eslachancegitbook-bot
authored andcommitted
GitBook: [master] 96 pages and 26 assets modified
1 parent dc045da commit 51177be

File tree

83 files changed

+853
-783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+853
-783
lines changed

.gitbook/assets/aigjoin.png

23.3 KB
Loading
16.2 KB
Loading

.gitbook/assets/cleverbot.png

41.2 KB
Loading

.gitbook/assets/djsjoin.png

23.8 KB
Loading

.gitbook/assets/editorhelp.png

3.13 KB
Loading

.gitbook/assets/embedexample1.png

31.5 KB
Loading

.gitbook/assets/embedexample2.png

71.1 KB
Loading

.gitbook/assets/gs1.png

20.4 KB
Loading

.gitbook/assets/gs2.png

27.9 KB
Loading

.gitbook/assets/gs4.png

26.6 KB
Loading

.gitbook/assets/gs5.png

15.9 KB
Loading

.gitbook/assets/gs6.png

12.3 KB
Loading

.gitbook/assets/permission.png

24.8 KB
Loading

.gitbook/assets/starboard.png

24.9 KB
Loading

.gitbook/assets/wh01.png

8.35 KB
Loading

.gitbook/assets/wh02.png

17.6 KB
Loading

.gitbook/assets/wh03.png

11.5 KB
Loading

.gitbook/assets/wh04.png

39.3 KB
Loading

.gitbook/assets/wh05.png

25.8 KB
Loading

.gitbook/assets/wh06.png

20.8 KB
Loading

.gitbook/assets/wh07.png

6.4 KB
Loading

.gitbook/assets/wh08.png

135 KB
Loading

.gitbook/assets/wh09.png

15.3 KB
Loading

.gitbook/assets/wh12.png

7.05 KB
Loading

.gitbook/assets/wh13.png

2.68 KB
Loading

.gitbook/assets/wh14.png

32 KB
Loading

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Discord.js Getting Started
1+
# Introduction
22

33
## Introduction
44

5-
This guidebook was originally authored by eslachance#4611 then handed down to me for future updates, but when she started the book originally it was because the examples for discord.js and the documentation were quite daunting for newcomers. There was definitely a space for this kind of document online, made obvious by the recurring questions that pop up almost every day on the support channels.
5+
This guidebook was originally authored by eslachance\#4611 then handed down to me for future updates, but when she started the book originally it was because the examples for discord.js and the documentation were quite daunting for newcomers. There was definitely a space for this kind of document online, made obvious by the recurring questions that pop up almost every day on the support channels.
66

77
Seeing as though there needed to be some more detailed explanations as well as code samples, She figured a guide would be a great place to start!
88

9-
To keep with the style of the official documentation, we will be using full terms (client and message) for those variables.
9+
To keep with the style of the official documentation, we will be using full terms \(client and message\) for those variables.
1010

1111
## Updating of this guide
1212

@@ -16,12 +16,15 @@ But to me Evie is a mentor, she was the one that metaphorically took me under he
1616

1717
And I am honoured to be continuing it.
1818

19-
![Guide transfer](assets/permission.png)
19+
![Guide transfer](.gitbook/assets/permission.png)
2020

2121
## Get Support
2222

2323
If you have any questions after reading this guide please join us on the official Discord.js server:
2424

25-
[![Join the Official Idiot's Guide Server](/assets/aigjoin.png)](https://discord.gg/gkZCQtH)[![Join the Official Discord.js Server](/assets/djsjoin.png)](https://discord.gg/bRCvFy9)
25+
![Join the Official Idiot's Guide Server](.gitbook/assets/aigjoin.png)
26+
27+
![Join the Official Discord.js Server](.gitbook/assets/djsjoin.png)
2628

2729
Last Updated: `21/01/2018`
30+

SUMMARY.md

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
1-
# Summary
1+
# Table of contents
22

3-
* [Support me on Patreon](https://www.patreon.com/anidiotsguide)
43
* [Introduction](README.md)
4+
* [Support me on Patreon](https://www.patreon.com/anidiotsguide)
5+
* [Introduction](introduction.md)
56
* [Frequently Asked Questions](frequently-asked-questions.md)
67
* [Common Errors](common-errors.md)
7-
* [Getting Started](getting-started.md)
8-
* [Getting Started - Long Version](getting-started/the-long-version.md)
9-
* [Getting Started - Linux TL;DR](getting-started/linux-tldr.md)
10-
* [Getting Started - Windows TL;DR](getting-started/windows-tldr.md)
11-
* [First Bot](first-bot.md)
12-
* [Your First Bot](getting-started/your-basic-bot.md)
13-
* [Adding a Config File](getting-started/config-json-file.md)
14-
* [Command with arguments](examples/command-with-arguments.md)
15-
* [A Basic Command Handler](coding-guides/a-basic-command-handler.md)
16-
* [Using Embeds in messages](examples/using-embeds-in-messages.md)
17-
* [Coding Guides](coding-guides.md)
18-
* [JSON-Based Points System](coding-guides/storing-data-in-a-json-file.md)
19-
* [SQLite-Based Points System](coding-guides/storing-data-in-an-sqlite-file.md)
20-
* [Enmap-Based Points System](coding-guides/storing-data-in-a-persistent-collection.md)
21-
* [Creating a Music Bot](coding-guides/coding-a-music-bot.md)
8+
* Getting Started
9+
* [Getting Started - Long Version](getting-started/getting-started-long-version.md)
10+
* [Getting Started - Linux TL;DR](getting-started/getting-started-linux-tl-dr.md)
11+
* [Getting Started - Windows TL;DR](getting-started/getting-started-windows-tl-dr.md)
12+
* First Bot
13+
* [Your First Bot](first-bot/your-first-bot.md)
14+
* [Adding a Config File](first-bot/adding-a-config-file.md)
15+
* [Command with arguments](first-bot/command-with-arguments.md)
16+
* [A Basic Command Handler](first-bot/a-basic-command-handler.md)
17+
* [Using Embeds in messages](first-bot/using-embeds-in-messages.md)
18+
* Coding Guides
19+
* [JSON-Based Points System](coding-guides/json-based-points-system.md)
20+
* [SQLite-Based Points System](coding-guides/sqlite-based-points-system.md)
21+
* [Enmap-Based Points System](coding-guides/enmap-based-points-system.md)
22+
* [Creating a Music Bot](coding-guides/creating-a-music-bot.md)
2223
* [Cleverbot Integration](coding-guides/cleverbot-integration.md)
23-
* [Selfbots, the greatest thing in the universe](examples/selfbots-are-awesome.md)
24+
* [Selfbots, the greatest thing in the universe](coding-guides/selfbots-the-greatest-thing-in-the-universe.md)
2425
* [Using Emojis](coding-guides/using-emojis.md)
25-
* [Starboard](coding-guides/starboard.md)
26-
* [Understanding](understanding.md)
27-
* [Events and Handlers](information/understanding-events-and-handlers.md)
28-
* [Collections](information/understanding-collections.md)
29-
* [Roles](information/understanding-roles.md)
30-
* [Sharding](information/understanding-sharding.md)
31-
* [Examples](examples.md)
26+
* [Making your own Starboard](coding-guides/starboard.md)
27+
* Understanding
28+
* [Events and Handlers](understanding/events-and-handlers.md)
29+
* [Collections](understanding/collections.md)
30+
* [Roles](understanding/roles.md)
31+
* [Sharding](understanding/sharding.md)
32+
* Examples
3233
* [Welcome Message every X users](examples/welcome-message-every-x-users.md)
3334
* [Message Reply Array](examples/message-reply-array.md)
3435
* [Making an Eval command](examples/making-an-eval-command.md)
35-
* [Miscellaneous Examples](examples/misc-examples.md)
36-
* [Using Guidebot's Flags](examples/using-guidebot-flags.md)
37-
* [Discord Webhooks](discord-webhooks.md)
38-
* [Discord Webhooks \(Part 1\)](discord-webhooks/part-1.md)
39-
* [Discord Webhooks \(Part 2\)](discord-webhooks/part-2.md)
40-
* [Discord Webhooks \(Part 3\)](discord-webhooks/part-3.md)
41-
* [Other Guides](other-guides.md)
36+
* [Miscellaneous Examples](examples/miscellaneous-examples.md)
37+
* [Using Guidebot's Flags](examples/using-guidebots-flags.md)
38+
* Discord Webhooks
39+
* [Discord Webhooks \(Part 1\)](discord-webhooks/discord-webhooks-part-1.md)
40+
* [Discord Webhooks \(Part 2\)](discord-webhooks/discord-webhooks-part-2.md)
41+
* [Discord Webhooks \(Part 3\)](discord-webhooks/discord-webhooks-part-3.md)
42+
* Other Guides
4243
* [Installing and Using a proper editor](other-guides/installing-and-using-a-proper-editor.md)
4344
* [Using Git to share and update code](other-guides/using-git-to-share-and-update-code.md)
44-
* [Hosting on a Raspberry Pi](other-guides/hosting-on-a-pi.md)
45-
* [Hosting Music Bots on a Raspberry Pi](other-guides/hosting-music-on-a-pi.md)
46-
* [Hosting on Glitch.com](other-guides/hosting-on-glitchcom.md)
47-
* [Async / Await](information/understanding-asyncawait.md)
48-
* [Docker Part 1: Setup & Dockerfile](other-guides/docker-01.md)
49-
* [Docker Part 2: Installing, running & More](other-guides/docker-02.md)
50-
* [Introducing Enhanced Maps](coding-guides/using-persistentcollections.md)
45+
* [Hosting on a Raspberry Pi](other-guides/hosting-on-a-raspberry-pi.md)
46+
* [Hosting Music Bots on a Raspberry Pi](other-guides/hosting-music-bots-on-a-raspberry-pi.md)
47+
* [Hosting on Glitch.com](other-guides/hosting-on-glitch.com.md)
48+
* [Async / Await](other-guides/async-await.md)
49+
* [Docker Part 1: Setup & Dockerfile](other-guides/docker-part-1-setup-and-dockerfile.md)
50+
* [Docker Part 2: Installing, running & More](other-guides/docker-part-2-installing-running-and-more.md)
51+
* [Introducing Enhanced Maps](other-guides/introducing-enhanced-maps.md)
5152
* [Introduction to modules](other-guides/introduction-to-modules.md)
52-
* [Video Guides](video-guides.md)
53-
* [Episode 1](video-guides/episode-01.md)
54-
* [Episode 2](video-guides/episode-02.md)
55-
* [Episode 3](video-guides/episode-03.md)
56-
* [Episode 4](video-guides/episode-04.md)
57-
* [Episode 5](video-guides/episode-05.md)
58-
* [Episode 6 Part 1](video-guides/episode-06-part-01.md)
59-
* [Episode 6 Part 2](video-guides/episode-06-part-02.md)
60-
* [Episode 7](video-guides/episode-07.md)
61-
* [Episode 8](video-guides/episode-08.md)
62-
* [Episode 9](video-guides/episode-09.md)
63-
* [Episode 10 Part 1](video-guides/episode-10-part-01.md)
64-
* [Episode 10 Part 2](video-guides/episode-10-part-02.md)
53+
* Video Guides
54+
* [Episode 1](video-guides/episode-1.md)
55+
* [Episode 2](video-guides/episode-2.md)
56+
* [Episode 3](video-guides/episode-3.md)
57+
* [Episode 4](video-guides/episode-4.md)
58+
* [Episode 5](video-guides/episode-5.md)
59+
* [Episode 6 Part 1](video-guides/episode-6-part-1.md)
60+
* [Episode 6 Part 2](video-guides/episode-6-part-2.md)
61+
* [Episode 7](video-guides/episode-7.md)
62+
* [Episode 8](video-guides/episode-8.md)
63+
* [Episode 9](video-guides/episode-9.md)
64+
* [Episode 10 Part 1](video-guides/episode-10-part-1.md)
65+
* [Episode 10 Part 2](video-guides/episode-10-part-2.md)
66+

coding-guides/cleverbot-integration.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
I've had this request since I started my Idiot's Guide, in fact it was one of the very first requests I had, but I had a feeling it would be a disappointing short episode, maybe a 5 minute long episode. But for a written guide it'd be perfect!
44

5-
So to get started, let's grab the example from [getting started](/getting-started/the-long-version.md) and shove it in a file.
5+
So to get started, let's grab the example from [getting started](../getting-started/getting-started-long-version.md) and shove it in a file.
66

7-
```js
7+
```javascript
88
const Discord = require("discord.js");
99
const client = new Discord.Client();
1010

@@ -23,7 +23,7 @@ client.login("superSecretBotTokenHere");
2323

2424
Once you've got that, we should go check out `cleverbot-node` on [npmjs.com](https://www.npmjs.com/package/cleverbot-node) and grab their example code
2525

26-
```js
26+
```javascript
2727
var Cleverbot = require("cleverbot-node");
2828
cleverbot = new Cleverbot;
2929
cleverbot.configure({botapi: "IAMKEY"});
@@ -32,7 +32,7 @@ cleverbot.write(cleverMessage, function (response) {
3232
});
3333
```
3434

35-
> **NOTE:** As you can see in the above example taken from the npm page, you now need an API key, which you can get [here](http://www.cleverbot.com/api/), they do offer a free tier, but that's 5,000 api calls per month (at the time of writing), and please note it says it's a free __trial__.
35+
> **NOTE:** As you can see in the above example taken from the npm page, you now need an API key, which you can get [here](http://www.cleverbot.com/api/), they do offer a free tier, but that's 5,000 api calls per month \(at the time of writing\), and please note it says it's a free **trial**.
3636
3737
Alright, we've got both parts we need, now before we continue we should get the module installed, just run `npm i cleverbot-node` with the `--save` flag if you have a `package.json` file \(and you should!\).
3838

@@ -44,14 +44,14 @@ We have both our example codes, now we need to combine them for a working bot.
4444
4545
Right, we need to take the first two lines of the cleverbot example...
4646

47-
```js
47+
```javascript
4848
var Cleverbot = require("cleverbot-node");
4949
cleverbot = new Cleverbot;
5050
```
5151

5252
...and put them with our discord definitions.
5353

54-
```js
54+
```javascript
5555
const Discord = require("discord.js");
5656
const Cleverbot = require("cleverbot-node");
5757
const client = new Discord.Client();
@@ -63,15 +63,15 @@ I renamed `cleverbot` to `clbot` to reduce any possible confusion between the va
6363

6464
Then we take the rest of the code and place that inside our message event handler, but for this example I only want the bot to talk to me in DM's, so we"ll check the channel `type` with the following code, you can make it respond on mentions or even in channels \(I would honestly advise against that.\)
6565

66-
```js
66+
```javascript
6767
if (message.channel.type === "dm") {
6868
// Cleverbot code goes here.
6969
}
7070
```
7171

7272
Your code should look something like this...
7373

74-
```js
74+
```javascript
7575
const Discord = require("discord.js");
7676
const Cleverbot = require("cleverbot-node");
7777
const client = new Discord.Client();
@@ -98,4 +98,5 @@ client.login("superSecretBotTokenHere");
9898

9999
If everything is as above, then just send your bot a DM and watch the magic unfold!
100100

101-
![Success!](/assets/cleverbot.png)
101+
![Success!](../.gitbook/assets/cleverbot.png)
102+
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
# Coding a Music Bot
1+
# Creating a Music Bot
22

33
Everyone including their grandparents want to create a music bot, I myself have created a music bot and believe me it's not as easy as you would think.
44

5-
However, if you insist on creating a music bot you can either check out the example bots below, or you could support me on Patreon for $5+, and you'll get a step by step tutorial on how to make a multi-guild compatible music bot and access to the completed source code to a custom music bot (When the series concludes).
5+
However, if you insist on creating a music bot you can either check out the example bots below, or you could support me on Patreon for $5+, and you'll get a step by step tutorial on how to make a multi-guild compatible music bot and access to the completed source code to a custom music bot \(When the series concludes\).
66

77
As well as the music bot tutorial you also get a `patron` role on my guild, a private patron only channel to discuss with other patrons, priority d.js bot help, behind the scenes pictures, videos and vlogs, and early access to regular content and future patron tutorial series.
88

9-
[![Support me on Patreon](/assets/becomeAPatronBanner.png)](https://www.patreon.com/anidiotsguide)
9+
![Support me on Patreon](../.gitbook/assets/becomeapatronbanner.png)
10+
11+
If you do not feel like supporting me, there are these amazing examples; [OhGodMusicBot](https://github.com/bdistin/OhGodMusicBot) by AoDude [Moosik](https://github.com/Gawdl3y/discord-moosik) by Gawdl3y [Commando's Music](https://github.com/iCrawl/Commando/tree/master/commands/music) by Crawl
1012

11-
If you do not feel like supporting me, there are these amazing examples;
12-
[OhGodMusicBot](https://github.com/bdistin/OhGodMusicBot) by AoDude
13-
[Moosik](https://github.com/Gawdl3y/discord-moosik) by Gawdl3y
14-
[Commando's Music](https://github.com/iCrawl/Commando/tree/master/commands/music) by Crawl

coding-guides/storing-data-in-a-persistent-collection.md renamed to coding-guides/enmap-based-points-system.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Similarly to the other _"Points System"_ articles, let's explore another altenat
1212
1313
Let's start with installing the 2 parts that we need for this to work: `enmap` and `enmap-sqlite`. Simply run the following command in your project folder:
1414

15-
```
15+
```text
1616
npm i enmap enmap-sqlite
1717
```
1818

1919
Once that's complete, we need to open up index.js and add two different things. First, we need to import and initialize the _Provider_ itself. Then, you need to create a new persistent Enmap using the provider itself. Here's how it goes:
2020

21-
```js
21+
```javascript
2222
const Enmap = require("enmap");
2323
const Provider = require("enmap-sqlite");
2424

@@ -31,9 +31,9 @@ That will create a new Enmap under the name of points, and attaches it to the cl
3131

3232
The obvious goal of a points system is to accumulate fake internet points and gloat about it. So, of course, that's going to be our first focus. In this example implementation, we will make the points guild-specific, and unuseable in DMs. Points will still accumulate even if the user does a command, which simplifies our code a bit.
3333

34-
Our starting point is a very basic message handler with pre-existing commands - such as what we see in the [Command with Arguments](/examples/command-with-arguments.md) page of this guide. The code is as such:
34+
Our starting point is a very basic message handler with pre-existing commands - such as what we see in the [Command with Arguments](../first-bot/command-with-arguments.md) page of this guide. The code is as such:
3535

36-
```js
36+
```javascript
3737
client.on("message", message => {
3838
if (message.author.bot) return;
3939
// This is where we'll put our code.
@@ -48,7 +48,7 @@ client.on("message", message => {
4848

4949
We do have a small caveat - we really don't want to react on Direct Messages, so our whole code will be in a block that checks for that:
5050

51-
```js
51+
```javascript
5252
client.on("message", message => {
5353
if (message.author.bot) return;
5454
if (message.guild) {
@@ -60,7 +60,7 @@ client.on("message", message => {
6060

6161
Our very first step is going to be to initialize a new entry in the enmap for any new user - one we haven't received a message from before. This is done using the `enmap.has(key)` method, which can check if a specific key exists in the Enmap, and `enmap.set(key, value)` method that adds data to Enmap. Note that our keys take the format of `guildid-userid` so they're unique to the guild and the user. Also, our data in this case is a complete object, which we'll take advantage of with Enmap 2.0.
6262

63-
```js
63+
```javascript
6464
client.on("message", message => {
6565
if (message.author.bot) return;
6666
if (message.guild) {
@@ -82,7 +82,7 @@ There's obviously a few ways we could have done this, including some fancy terna
8282

8383
Two methods will be used for the following bit, `enmap.getProp(key, propname)` which retrieves, specifically, only the points property from the saved object. We'll also use `enmap.setProp(key, propname, value)` which will then _save_ that points property back into the enmap without needing to load the whole object.
8484

85-
```js
85+
```javascript
8686
client.on("message", message => {
8787
if (message.author.bot) return;
8888
if (message.guild) {
@@ -104,29 +104,29 @@ client.on("message", message => {
104104

105105
Time to level up! If a user has enough points, they will go up a level. Now we have to do some math here, but don't run off in fear, this one's pretty easy. This is how we calculate the levels:
106106

107-
```js
107+
```javascript
108108
const curLevel = Math.floor(0.1 * Math.sqrt(currentPoints));
109109
```
110110

111111
This line will calculate the square root of `currentPoints` then multiplies that result by 0.1 then floors that result for a round number.
112112

113113
Now we should work out if you've amassed enough points to actually level up, by grabbing the current user's level and comparing them. If the new calculated level is higher, it means the user leveled up and we can deal with that, first by sending them a very annoying mee6-inspired message!
114114

115-
```js
115+
```javascript
116116
if (client.points.getProp(key, "level") < curLevel) {
117117
message.reply(`You've leveled up to level **${curLevel}**! Ain't that dandy?`);
118118
}
119119
```
120120

121121
Lastly, we want to update the `score.level` value with the new level so throw this under the `message.reply`.
122122

123-
```js
123+
```javascript
124124
client.points.setProp (key, "level", curLevel);
125125
```
126126

127127
So here's the whole thing from top to bottom, with bonus comments!
128128

129-
```js
129+
```javascript
130130
client.on("message", message => {
131131
// As usual, ignore all bots.
132132
if (message.author.bot) return;
@@ -171,7 +171,7 @@ Alright, that's the bulk of the code, you could throw this into your bot and it
171171
172172
So let's re-iterate our current starting position.
173173

174-
```js
174+
```javascript
175175
client.on("message", message => {
176176
if (message.author.bot) return;
177177
if (message.guild) { /* Points Code Here */ }
@@ -186,7 +186,7 @@ client.on("message", message => {
186186

187187
The `points` command would look like this:
188188

189-
```js
189+
```javascript
190190
if (command === "points") {
191191
return message.channel.send(`You currently have ${client.points.getProp(key, "points")}, and are level ${client.points.getProp(key, "level")}!`);
192192
}
@@ -200,7 +200,7 @@ Let's finish this off with a very simple `leaderboard` command that will show th
200200
201201
So here's our leaderboard command:
202202

203-
```js
203+
```javascript
204204
if(command === "leaderboard") {
205205
// Get a filtered list (for this guild only), and convert to an array while we're at it.
206206
const filtered = client.points.filterArray( p => p.guildID === message.guild.id );
@@ -230,7 +230,7 @@ In the famous words of Evie _"Now take this, and make it **better than Mee6!** G
230230

231231
Taken straight from [Evie's Gist on points](https://gist.github.com/eslachance/12e2239aa353b350e075a4b006238335) \(but adjusted for Enmap 2.0\), you might find these useful!
232232

233-
```js
233+
```javascript
234234
if(command === "give") {
235235
// Limited to guild owner - adjust to your own preference!
236236
if(!message.author.id === message.guild.owner) return message.reply("You're not the boss of me, you can't do that!");
@@ -271,4 +271,5 @@ Taken straight from [Evie's Gist on points](https://gist.github.com/eslachance/1
271271

272272
message.channel.send(`I've cleaned up ${toRemove.size} old farts.`);
273273
}
274-
```
274+
```
275+

0 commit comments

Comments
 (0)