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:
commit
2adfa02f0d
@ -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,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
docs/setup/bots/usage.md
Normal file
39
docs/setup/bots/usage.md
Normal 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
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user