Skip to content

Commit 2adfa02

Browse files
Merge pull request #90 from DEVTomatoCake/feat/application-docs
Improve application/bot docs
2 parents fe51b8d + 18783a6 commit 2adfa02

File tree

2 files changed

+68
-21
lines changed

2 files changed

+68
-21
lines changed

docs/setup/bots/index.md

+29-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Bots and Applications
22

3-
{{ project.name }} is backwards-compatibile with Discord.com, and so all
3+
{{ project.name }} is compatible with Discord.com, and so all
44
existing bots and applications designed for Discord.com should work relatively easily
55
when connected to a {{ project.name }} instance instead.
66

7-
The Discord Developer Panel is available at /developers, and allows you all the same functionality
8-
to create bots and applications on a {{ project.name }} instance as Discord.com.
9-
107
## Bot Libraries
118

9+
Below are some popular libraries for connecting bots to a {{ project.name }} instance.
10+
11+
Make sure to replace `api.{{ project.domain }}` and `cdn.{{ project.domain }}`
12+
with the appropriate URLs of the instance you want to connect to.
13+
14+
You can get them from a client or from the [well-known](server/wellknown) instance endpoint.
15+
1216
### Discord.js
1317

1418
The `Client` class constructor accepts a `http` object, which you can use to change
@@ -18,12 +22,15 @@ the endpoints used.
1822
const { Client } = require("discord.js");
1923

2024
const client = new Client({
21-
http: {
22-
version: 9,
23-
api: "https://api.{{ project.domain }}",
25+
rest: {
26+
api: "https://api.{{ project.domain }}/api",
2427
cdn: "https://cdn.{{ project.domain }}",
25-
invite: "https://{{ project.domain }}/invite",
28+
version: "9"
2629
},
30+
ws: {
31+
version: 9
32+
},
33+
// intents, ...
2734
});
2835

2936
client.login("your token here");
@@ -34,28 +41,29 @@ client.login("your token here");
3441
```py
3542
import discord
3643

37-
discord.http.Route.BASE = "https://api.{{ project.domain }}"
44+
discord.http.Route.BASE = "https://api.{{ project.domain }}/api"
3845
client = discord.Client()
3946

40-
client.run('your token here')
47+
client.run("your token here")
4148
```
4249

4350
### JDA
51+
4452
1. Create a RestConfig instance: `RestConfig restConfig = new RestConfig();`
45-
2. Use RestConfig#setBaseUrl to tell JDA what your Rest URI is (this NEEDS to include /api/<apiver>, because it's the api **base** url for all requests): `restConfig.setBaseUrl("https://{REPLACE HERE WITH YOUR API SERVER URL}/api/v9");`
53+
2. Use RestConfig#setBaseUrl to tell JDA what your Rest URI is: `restConfig.setBaseUrl("https://api.{{ project.domain }}/api/v9");`
4654
3. Create another class, and extend ConcurrentSessionController, e.g. `public class SpacebarSessionController extends ConcurrentSessionController`
4755
4. Override the ConcurrentSessionController#getGateway method:
4856
```java
49-
@NotNull
50-
@Override
51-
public String getGateway() {
52-
return "wss://{REPLACE HERE WITH YOUR GATEWAY SERVER URL}/?encoding=json&v=9&compress=zlib-stream";
53-
}
57+
@NotNull
58+
@Override
59+
public String getGateway() {
60+
return "wss://{REPLACE HERE WITH YOUR GATEWAY SERVER URL}/?encoding=json&v=9&compress=zlib-stream";
61+
}
5462
```
5563
5. Finally, configure JDA to use your RestConfig & SpacebarSessionController, like this:
5664
```java
57-
JDA jda = JDABuilder.createDefault("not_a_real_token_lol")
58-
.setRestConfig(restConfig)
59-
.setSessionController(new SpacebarSessionController())
60-
.build();
61-
```
65+
JDA jda = JDABuilder.createDefault("your token here")
66+
.setRestConfig(restConfig)
67+
.setSessionController(new SpacebarSessionController())
68+
.build();
69+
```

docs/setup/bots/usage.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Bot and application usage
2+
3+
## Creating an application
4+
5+
If your client doesn't have a Developer Portal (yet), you can use the below API requests to create an application.
6+
Make sure to replace the instance API URL if it's different.
7+
8+
1. Create an application:
9+
```http
10+
POST https://api.{{ project.domain }}/api/v9/applications
11+
Authorization: <User token, e.g. from initial Gateway connection to instance>
12+
Content-Type: application/json
13+
14+
{
15+
"name": "My Application"
16+
}
17+
```
18+
2. Note the returned `id`.
19+
3. Create a bot:
20+
```http
21+
POST https://api.{{ project.domain }}/api/v9/applications/<id>/bot
22+
Authorization: <User token>
23+
```
24+
25+
This will return a token for you to use.
26+
27+
## Adding an application to a server
28+
29+
```http
30+
POST https://api.{{ project.domain }}/api/v9/oauth2/authorize?client_id=<id>
31+
Authorization: <User token of server owner/member with Manage Guild permissions>
32+
Content-Type: application/json
33+
34+
{
35+
"guild_id": "<server ID>",
36+
"permissions": "<permission BigInt, e.g. 0 for no permissions or 8 for Administrator>",
37+
"authorize": true
38+
}
39+
```

0 commit comments

Comments
 (0)