import { fetch } from "https://esm.town/v/std/fetch";
export let registerDiscordCommands = async (
app_id: String,
guild_id: String | undefined | null,
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();
};