diff options
| author | Fuwn <[email protected]> | 2025-09-07 02:28:34 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-07 02:28:34 -0700 |
| commit | 188c714f43635fb57eac70b167dba682d6b93a2f (patch) | |
| tree | 28a5bc64a6a8efd78c19cdaa666b98e42d3b90b5 /src/register.ts | |
| parent | feat: Add top command (diff) | |
| download | umabotdiscord-188c714f43635fb57eac70b167dba682d6b93a2f.tar.xz umabotdiscord-188c714f43635fb57eac70b167dba682d6b93a2f.zip | |
build: Switch to TypeScript
Diffstat (limited to 'src/register.ts')
| -rw-r--r-- | src/register.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/register.ts b/src/register.ts new file mode 100644 index 0000000..632b2b8 --- /dev/null +++ b/src/register.ts @@ -0,0 +1,62 @@ +import { + HOT_COMMAND, + NSFW_COMMAND, + ROLEPLAY_COMMAND, + TOP_COMMAND, + type DiscordCommand, +} from './commands.js'; +import dotenv from 'dotenv'; +import process from 'node:process'; + +dotenv.config({ path: '.dev.vars' }); + +const token = process.env.DISCORD_TOKEN; +const applicationID = process.env.DISCORD_APPLICATION_ID; + +if (!token) + throw new Error('The DISCORD_TOKEN environment variable is required.'); + +if (!applicationID) + throw new Error( + 'The DISCORD_APPLICATION_ID environment variable is required.', + ); + +const url = `https://discord.com/api/v10/applications/${applicationID}/commands`; + +const commands: DiscordCommand[] = [ + HOT_COMMAND, + ROLEPLAY_COMMAND, + NSFW_COMMAND, + TOP_COMMAND, +]; + +const response = await fetch(url, { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bot ${token}`, + }, + method: 'PUT', + body: JSON.stringify(commands), +}); + +if (response.ok) { + console.log('Registered all commands'); + + const data = await response.json(); + + console.log(JSON.stringify(data, null, 2)); +} else { + console.error('Error registering commands'); + + let errorText = `Error registering commands \n ${response.url}: ${response.status} ${response.statusText}`; + + try { + const error = await response.text(); + + if (error) errorText = `${errorText} \n\n ${error}`; + } catch (error) { + console.error('Error reading body from request:', error); + } + + console.error(errorText); +} |