summaryrefslogtreecommitdiff
path: root/src/register.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/register.ts')
-rw-r--r--src/register.ts62
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);
+}