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

Merge pull request #90 from DEVTomatoCake/feat/application-docs

Improve application/bot docs
This commit is contained in:
Madeline 2024-07-22 09:12:43 +10:00 committed by GitHub
commit 2adfa02f0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 68 additions and 21 deletions

View File

@ -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
@ -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");
@ -34,15 +41,16 @@ 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
@ -54,7 +62,7 @@ client.run('your token here')
```
5. Finally, configure JDA to use your RestConfig & SpacebarSessionController, like this:
```java
JDA jda = JDABuilder.createDefault("not_a_real_token_lol")
JDA jda = JDABuilder.createDefault("your token here")
.setRestConfig(restConfig)
.setSessionController(new SpacebarSessionController())
.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
}
```