Skip to content

Commit 24f1eab

Browse files
DiamondLionLVDiamondLionLV
authored andcommitted
upload
1 parent dfde3fc commit 24f1eab

File tree

4 files changed

+238
-0
lines changed

4 files changed

+238
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Welcome
2+
3+
## Introduction
4+
5+
This guide makes a best effort attempt at humanizing the use of the Discord.js library, in its current version 13 iteration.
6+
7+
In this guide we make every effort to _teach_ you how to use the library and how to extend it with your own code. We do, however expect you to have a basic understanding of JavaScript before attempting to write bots. Discord.js \(and other discord libraries\) require some median-to-advanced concepts that might be hard to grasp for anyone that doesn't have a good footing with the language.
8+
9+
## Get Support
10+
11+
If you have any questions after reading this guide, please don't hesitate to join us on our [Discord server](https://icebee.xyz/discord), "Icebee Development".

SUMMARY.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Table of contents
2+
3+
* [Welcome](README.md)
4+
* [Frequently Asked Questions](frequently-asked-questions.md)
5+
* [Common Errors](common-errors.md)
6+
* [Getting Started](getting-started/README.md)
7+
* [Getting Started - Long Version](getting-started/getting-started-long-version.md)
8+
* [Getting Started - TL;DR](getting-started/getting-started-tl-dr.md)
9+
* [First Bot](first-bot/README.md)
10+
* [Your First Bot](first-bot/your-first-bot.md)
11+
* [Adding a Config File](first-bot/adding-a-config-file.md)
12+
* [Command with arguments](first-bot/command-with-arguments.md)
13+
* [A Basic Command Handler](first-bot/a-basic-command-handler.md)
14+
* [A Better Basic Command Handler](first-bot/better-basic-handler.md)
15+
* [Using Embeds in messages](first-bot/using-embeds-in-messages.md)
16+
* [Coding Guides](coding-guides/README.md)
17+
* [SQLite-Based Points System](coding-guides/sqlite-based-points-system.md)
18+
* [Cleverbot Integration](coding-guides/cleverbot-integration.md)
19+
* [Understanding](understanding/README.md)
20+
* [Events and Handlers](understanding/events-and-handlers.md)
21+
* [Collections](understanding/collections.md)
22+
* [Roles and Permissions](understanding/roles.md)
23+
* [Sharding](understanding/sharding.md)
24+
* [Examples](examples/README.md)
25+
* [Making an Eval command](examples/making-an-eval-command.md)
26+
* [Miscellaneous Examples](examples/miscellaneous-examples.md)
27+
* [Discord Webhooks](discord-webhooks/README.md)
28+
* [Webhooks \(Part 1\)](discord-webhooks/discord-webhooks-part-1.md)
29+
* [Webhooks \(Part 2\)](discord-webhooks/discord-webhooks-part-2.md)
30+
* [Webhooks \(Part 3\)](discord-webhooks/discord-webhooks-part-3.md)
31+
* [Other Guides](other-guides/README.md)
32+
* [Using Git to share and update code](other-guides/using-git-to-share-and-update-code.md)
33+
* [Using Environment Variables](other-guides/env-files.md)
34+
* [Async / Await](other-guides/async-await.md)
35+

common-errors.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Common Errors
2+
3+
## Cannot find module `discord.js`
4+
5+
### Problem:
6+
7+
You didn't install Discord.js or installed it in the wrong folder.
8+
9+
### Solution:
10+
11+
* Make sure you are in the **correct** folder where you have your bot's files
12+
* SHIFT+Right-Click in the folder and select **Open command window here**
13+
* Run `npm init -y`, and hit enter until the wizard is complete
14+
* Run `npm i discord.js` again to install Discord.
15+
16+
## `Error: getaddrinfo ENOTFOUND gateway.discord.gg gateway.discord.gg:443`
17+
18+
### Problem:
19+
20+
Your internet went down.
21+
22+
### Solution:
23+
24+
Get better, more stable internet, or host your bot on a VPS.
25+
26+
## Unexpected End of Input
27+
28+
### Problem:
29+
30+
```text
31+
});
32+
^
33+
SyntaxError: Unexpected end of input
34+
```
35+
36+
### Solution:
37+
38+
Your code has an error somewhere. This is _impossible_ to troubleshoot without the **complete** code, since the error can be anywhere \(in fact the error stack often tells you it's at the end of your code\).
39+
40+
The following trick is a lifesaver, so pay attention: Your code editor is trying to help you. Whatever editor you're using \(except notepad++.exe. Don't use notepad++!\), clicking on any \(and I mean any\) special character such as parentheses, square brackets, curly braces, double and single quotes, will automatically highlight the one that matches it. The screenshot below shows this: I clicked on the curly brace at the bottom, it shows me the one on top by highlighting it. Learn this, and how different functions and event handlers "look" like.
41+
42+
![They have friends](https://i.imgur.com/x1T55kY.png)
43+
44+
You can check out [Installing and Using a Proper Editor](other-guides/installing-and-using-a-proper-editor.md) to help in at least knowing there are errors _before_ running your bot code.

frequently-asked-questions.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Frequently Asked Questions
2+
3+
In this page, some very basic, frequently-asked questions are answered. It's important to understand that **these examples are generic** and will most likely not work if you just copy/paste them in your code. You need to **understand** these lines, not just blindly shove them in your code.
4+
5+
## Code Examples
6+
7+
## Bot and Bot Client
8+
9+
```javascript
10+
// Set the bot's "Playing: " status (must be in an event!)
11+
client.on("ready", () => {
12+
client.user.setActivity("my code", { type: "WATCHING"})
13+
})
14+
```
15+
16+
```javascript
17+
// Set the bot's online/idle/dnd/invisible status
18+
client.on("ready", () => {
19+
client.user.setStatus("online");
20+
});
21+
```
22+
23+
```javascript
24+
// Set the bot's presence (activity and status)
25+
client.on("ready", () => {
26+
client.user.setPresence({
27+
activities: [{
28+
name: "my code",
29+
type: "WATCHING"
30+
}],
31+
status: "idle"
32+
})
33+
})
34+
```
35+
36+
Note: You can find a list of all possible activity types [here](https://discord.js.org/#/docs/main/stable/typedef/ActivityType).
37+
38+
If you want your bot's status to show up as `STREAMING`, you need to provide a Twitch or YouTube URL.
39+
For `setActivity`, you need to provide an options object, which needs to have the URL, and the type should be set to streaming.
40+
For `setPresence`, you need to provide the presence data object, which needs to contain the activities array, with the url and type \(Set it to "STREAMING"\).
41+
42+
```javascript
43+
client.on("ready", () => {
44+
client.user.setActivity("my code", { type: "STREAMING", url: "https://www.twitch.tv/DiamondLions" })
45+
})
46+
```
47+
48+
## Users and Members
49+
50+
In these examples `Guild` is a placeholder for where you get the guild. This can be `message.guild` or `member.guild` or just `guild` depending on the event. Or, you can get the guild by ID \(see next section\) and use that, too!
51+
52+
```javascript
53+
// Get a User by ID
54+
client.users.cache.get("user id here");
55+
// Returns <User>
56+
```
57+
58+
```javascript
59+
// Get a Member by ID
60+
message.guild.members.cache.get("user ID here");
61+
// Returns <Member>
62+
```
63+
64+
```javascript
65+
// Get a Member from message Mention
66+
message.mentions.members.first();
67+
// Returns <Member>, if there is a mentioned member
68+
```
69+
70+
```javascript
71+
// Send a Direct Message to a user
72+
message.author.send("hello");
73+
// With Member it works too:
74+
message.member.send("Heya!");
75+
```
76+
77+
```javascript
78+
// Mention a user in a message
79+
message.channel.send(`Hello ${message.author.toString()}, and welcome!`);
80+
// or
81+
message.channel.send("Hello " + message.author.toString() + ", and welcome!");
82+
```
83+
84+
```javascript
85+
// Restrict a command to a specific user by ID
86+
if (message.content.startsWith(`${prefix}commandname`)) {
87+
if (message.author.id !== "A user ID") return;
88+
// Your Command Here
89+
}
90+
```
91+
92+
```javascript
93+
message.guild.members.fetch(message.author)
94+
.then(member => {
95+
// The member is available here.
96+
})
97+
.catch(() => {
98+
// When an error occurs.
99+
})
100+
```
101+
102+
## Channels and Guilds
103+
104+
```javascript
105+
// Get a Guild by ID
106+
client.guilds.cache.get("the guild id");
107+
// Returns <Guild>
108+
```
109+
110+
```javascript
111+
// Get a Channel by ID
112+
client.channels.cache.get("the channel id");
113+
// Returns <Channel>
114+
```
115+
116+
```javascript
117+
// Get a Channel by Name
118+
message.guild.channels.cache.find(channel => channel.name === "channel-name");
119+
// returns <Channel>
120+
```
121+
122+
```javascript
123+
// Create an invite and send it in the channel
124+
// You can only create an invite from a GuildChannel
125+
// Messages can only be sent to a TextChannel
126+
message.guild.channels.cache.get('<CHANNEL ID>').createInvite().then(invite =>
127+
message.channel.send(invite.url)
128+
);
129+
```
130+
131+
## Messages
132+
133+
```javascript
134+
// Editing a message the bot sent
135+
message.channel.send("Test").then(sentMessage => sentMessage.edit("Blah"));
136+
// message now reads : "Blah"
137+
```
138+
139+
```javascript
140+
message.channel.messages.fetch("352292052538753025")
141+
.then(message => {
142+
// do something with it
143+
// Check if the author of the message is the bot
144+
if (message.client.user.id !== message.id) return console.log("I'm not the author of that message!");
145+
// Edit the message
146+
message.edit("This fetched message was edited");
147+
});
148+
```

0 commit comments

Comments
 (0)