1
0
mirror of https://github.com/spacebarchat/docs.git synced 2024-11-08 11:22:31 +01:00

Improve application/bot docs

This commit is contained in:
TomatoCake 2024-07-19 14:09:51 +02:00
parent fe51b8d6fe
commit 18783a697e
2 changed files with 68 additions and 21 deletions

View File

@ -1,14 +1,18 @@
# Bots and Applications # 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 existing bots and applications designed for Discord.com should work relatively easily
when connected to a {{ project.name }} instance instead. 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 ## 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 ### Discord.js
The `Client` class constructor accepts a `http` object, which you can use to change The `Client` class constructor accepts a `http` object, which you can use to change
@ -18,12 +22,15 @@ the endpoints used.
const { Client } = require("discord.js"); const { Client } = require("discord.js");
const client = new Client({ const client = new Client({
http: { rest: {
version: 9, api: "https://api.{{ project.domain }}/api",
api: "https://api.{{ project.domain }}",
cdn: "https://cdn.{{ project.domain }}", cdn: "https://cdn.{{ project.domain }}",
invite: "https://{{ project.domain }}/invite", version: "9"
}, },
ws: {
version: 9
},
// intents, ...
}); });
client.login("your token here"); client.login("your token here");
@ -34,28 +41,29 @@ client.login("your token here");
```py ```py
import discord import discord
discord.http.Route.BASE = "https://api.{{ project.domain }}" discord.http.Route.BASE = "https://api.{{ project.domain }}/api"
client = discord.Client() client = discord.Client()
client.run('your token here') client.run("your token here")
``` ```
### JDA ### JDA
1. Create a RestConfig instance: `RestConfig restConfig = new RestConfig();` 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` 3. Create another class, and extend ConcurrentSessionController, e.g. `public class SpacebarSessionController extends ConcurrentSessionController`
4. Override the ConcurrentSessionController#getGateway method: 4. Override the ConcurrentSessionController#getGateway method:
```java ```java
@NotNull @NotNull
@Override @Override
public String getGateway() { public String getGateway() {
return "wss://{REPLACE HERE WITH YOUR GATEWAY SERVER URL}/?encoding=json&v=9&compress=zlib-stream"; 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: 5. Finally, configure JDA to use your RestConfig & SpacebarSessionController, like this:
```java ```java
JDA jda = JDABuilder.createDefault("not_a_real_token_lol") JDA jda = JDABuilder.createDefault("your token here")
.setRestConfig(restConfig) .setRestConfig(restConfig)
.setSessionController(new SpacebarSessionController()) .setSessionController(new SpacebarSessionController())
.build(); .build();
``` ```

39
docs/setup/bots/usage.md Normal file
View File

@ -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
}
```