summaryrefslogtreecommitdiff
path: root/src/register.js
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-06 16:51:26 -0700
committerFuwn <[email protected]>2025-09-06 16:51:26 -0700
commitb625aff7160c593646efaf080163f96f69aa6391 (patch)
tree163d5096e3145bcb0b0bf8feba5ab35ef12c9f62 /src/register.js
downloadumabotdiscord-b625aff7160c593646efaf080163f96f69aa6391.tar.xz
umabotdiscord-b625aff7160c593646efaf080163f96f69aa6391.zip
feat: Initial commit
Diffstat (limited to 'src/register.js')
-rw-r--r--src/register.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/register.js b/src/register.js
new file mode 100644
index 0000000..a9a5deb
--- /dev/null
+++ b/src/register.js
@@ -0,0 +1,49 @@
+import { HOT_COMMAND, ROLEPLAY_COMMAND } 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 response = await fetch(url, {
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bot ${token}`,
+ },
+ method: 'PUT',
+ body: JSON.stringify([HOT_COMMAND, ROLEPLAY_COMMAND]),
+});
+
+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);
+}