Skip to content

Commit

Permalink
Merge pull request #90 from DEVTomatoCake/feat/application-docs
Browse files Browse the repository at this point in the history
Improve application/bot docs
  • Loading branch information
MaddyUnderStars authored Jul 21, 2024
2 parents fe51b8d + 18783a6 commit 2adfa02
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 21 deletions.
50 changes: 29 additions & 21 deletions docs/setup/bots/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Bots and Applications

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

The Discord Developer Panel is available at /developers, and allows you all the same functionality
to create bots and applications on a {{ project.name }} instance as Discord.com.

## Bot Libraries

Below are some popular libraries for connecting bots to a {{ project.name }} instance.

Make sure to replace `api.{{ project.domain }}` and `cdn.{{ project.domain }}`
with the appropriate URLs of the instance you want to connect to.

You can get them from a client or from the [well-known](server/wellknown) instance endpoint.

### Discord.js

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

const client = new Client({
http: {
version: 9,
api: "https://api.{{ project.domain }}",
rest: {
api: "https://api.{{ project.domain }}/api",
cdn: "https://cdn.{{ project.domain }}",
invite: "https://{{ project.domain }}/invite",
version: "9"
},
ws: {
version: 9
},
// intents, ...
});

client.login("your token here");
Expand All @@ -34,28 +41,29 @@ client.login("your token here");
```py
import discord

discord.http.Route.BASE = "https://api.{{ project.domain }}"
discord.http.Route.BASE = "https://api.{{ project.domain }}/api"
client = discord.Client()

client.run('your token here')
client.run("your token here")
```

### JDA

1. Create a RestConfig instance: `RestConfig restConfig = new RestConfig();`
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");`
2. Use RestConfig#setBaseUrl to tell JDA what your Rest URI is: `restConfig.setBaseUrl("https://api.{{ project.domain }}/api/v9");`
3. Create another class, and extend ConcurrentSessionController, e.g. `public class SpacebarSessionController extends ConcurrentSessionController`
4. Override the ConcurrentSessionController#getGateway method:
```java
@NotNull
@Override
public String getGateway() {
return "wss://{REPLACE HERE WITH YOUR GATEWAY SERVER URL}/?encoding=json&v=9&compress=zlib-stream";
}
@NotNull
@Override
public String getGateway() {
return "wss://{REPLACE HERE WITH YOUR GATEWAY SERVER URL}/?encoding=json&v=9&compress=zlib-stream";
}
```
5. Finally, configure JDA to use your RestConfig & SpacebarSessionController, like this:
```java
JDA jda = JDABuilder.createDefault("not_a_real_token_lol")
.setRestConfig(restConfig)
.setSessionController(new SpacebarSessionController())
.build();
```
JDA jda = JDABuilder.createDefault("your token here")
.setRestConfig(restConfig)
.setSessionController(new SpacebarSessionController())
.build();
```
39 changes: 39 additions & 0 deletions docs/setup/bots/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Bot and application usage

## Creating an application

If your client doesn't have a Developer Portal (yet), you can use the below API requests to create an application.
Make sure to replace the instance API URL if it's different.

1. Create an application:
```http
POST https://api.{{ project.domain }}/api/v9/applications
Authorization: <User token, e.g. from initial Gateway connection to instance>
Content-Type: application/json

{
"name": "My Application"
}
```
2. Note the returned `id`.
3. Create a bot:
```http
POST https://api.{{ project.domain }}/api/v9/applications/<id>/bot
Authorization: <User token>
```

This will return a token for you to use.

## Adding an application to a server

```http
POST https://api.{{ project.domain }}/api/v9/oauth2/authorize?client_id=<id>
Authorization: <User token of server owner/member with Manage Guild permissions>
Content-Type: application/json
{
"guild_id": "<server ID>",
"permissions": "<permission BigInt, e.g. 0 for no permissions or 8 for Administrator>",
"authorize": true
}
```

0 comments on commit 2adfa02

Please sign in to comment.