This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannounce.ts
37 lines (33 loc) · 1.53 KB
/
announce.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
import updateEmbed from './documents/json/update.json';
import { Routes } from 'discord-api-types/v9';
import { REST } from '@discordjs/rest';
import dotenv from 'dotenv';
import chalk from 'chalk';
const isTest = process.argv.includes("--test");
dotenv.config({ path: isTest ? ".env.local" : ".env" });
const botToken = process.env.DISCORD_BOT_TOKEN;
if (botToken === undefined) throw new Error("DISCORD_BOT_TOKEN must be provided!");
const rest = new REST({ version: '9' }).setToken(botToken);
void async function () {
try {
console.log("Sending announcement...");
let fullRoute: `/${string}`;
if (isTest) {
const channelId = process.env.TEST_CHANNEL_ID;
if (channelId === undefined) throw new Error("TEST_CHANNEL_ID must be provided!");
fullRoute = Routes.channelMessages(channelId);
} else {
const webhookId = process.env.ANNOUNCEMENT_WEBHOOK_ID;
if (webhookId === undefined) throw new Error("ANNOUNCEMENT_WEBHOOK_ID must be provided!");
const webhookToken = process.env.ANNOUNCEMENT_WEBHOOK_TOKEN;
if (webhookToken === undefined) throw new Error("ANNOUNCEMENT_WEBHOOK_TOKEN must be provided!");
fullRoute = Routes.webhook(webhookId, webhookToken);
}
const body = { embeds: [updateEmbed] };
await rest.post(fullRoute, { body });
console.log(chalk.green("Succesfully sent announcement!"));
}
catch (error) {
console.error(chalk.red("Failed to send announcement:"), error);
}
}();