Public
Script
Forked from mattx/register_discord_commands
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { fetch } from "https://esm.town/v/std/fetch";
export let register_discord_commands = async (
app_id: String,
guild_id: ?String,
token: String,
commands: Array<Object>
) => {
let url = `https://discord.com/api/v10/applications/${app_id}/`;
if (guild_id) {
url += `guilds/${guild_id}/commands`;
} else {
url += `commands`;
}
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Authorization: `Bot ${token}`,
},
method: "PUT",
body: JSON.stringify(commands),
});
return response.ok || response.text();
};
// Forked from @mattx.register_discord_commands
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023