Skip to content

Commit e6738de

Browse files
authored
Merge pull request AnIdiotsGuide#129 from ookamicodes/patch-1
Other method of config with JSON
2 parents 9f902fe + 65bc5e4 commit e6738de

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

first-bot/adding-a-config-file.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ const Discord = require("discord.js");
3535
const client = new Discord.Client();
3636
const config = require("./config.json");
3737
```
38-
38+
or methode 2
39+
```javascript
40+
const { token, prefix } = require("./config.json");
41+
```
3942
This means that now, `config` is your configuration object. `config.token` is your token, `config.prefix` is your prefix! Simple enough.
43+
With the other methode you only need to type `token`or `prefix` to get the data from the JSON file.
4044

4145
## Step 3: Using `config` in your code
4246

@@ -87,6 +91,32 @@ client.on("message", (message) => {
8791
The removal of the line that sets the prefix. We don't need it anymore!
8892
{% endhint %}
8993

94+
## Using `token`, `prefix` in your code
95+
96+
Its the same thing like above. The only one that change is, that you don't need `config`.`(data)`.
97+
You only need to use `token`for the bot token and `prefix`for the bot prefix.
98+
99+
#### Usage example of `token`
100+
101+
```javascript
102+
client.login(token);
103+
```
104+
105+
#### Usage example of `prefix`
106+
107+
```javascript
108+
client.on("message", (message) => {
109+
if (!message.content.startsWith(prefix) || message.author.bot) return;
110+
111+
if (message.content.startsWith(prefix + "ping")) {
112+
message.channel.send("pong!");
113+
} else
114+
if (message.content.startsWith(prefix + "foo")) {
115+
message.channel.send("bar!");
116+
}
117+
});
118+
```
119+
90120
## Changing the config
91121

92122
If you're asking yourself "but how do I change the prefix, now?" fear not, we have some help for you. We suggest you start by reading the rest of this section of the guide \("First Bot"\) and then hop on to the [Per-Server Configuration Guide on the Enmap Documentation](https://enmap.evie.codes/examples/settings)!

0 commit comments

Comments
 (0)