From 18783a697e94629999f67ae6553c713eb2d614bf Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:09:51 +0200 Subject: [PATCH] Improve application/bot docs --- docs/setup/bots/index.md | 50 +++++++++++++++++++++++----------------- docs/setup/bots/usage.md | 39 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 docs/setup/bots/usage.md diff --git a/docs/setup/bots/index.md b/docs/setup/bots/index.md index ce0b583..a0cfdcc 100644 --- a/docs/setup/bots/index.md +++ b/docs/setup/bots/index.md @@ -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/, 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(); -``` \ No newline at end of file +JDA jda = JDABuilder.createDefault("your token here") + .setRestConfig(restConfig) + .setSessionController(new SpacebarSessionController()) + .build(); +``` diff --git a/docs/setup/bots/usage.md b/docs/setup/bots/usage.md new file mode 100644 index 0000000..ab4a702 --- /dev/null +++ b/docs/setup/bots/usage.md @@ -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: + 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//bot + Authorization: + ``` + +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= +Authorization: +Content-Type: application/json + +{ + "guild_id": "", + "permissions": "", + "authorize": true +} +```