This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
Files
scoresaber-reloadedv3/projects/backend/src/bot/bot.ts

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-10-25 16:49:38 +00:00
import { Client } from "discordx";
import { ActivityType, EmbedBuilder } from "discord.js";
import { Config } from "@ssr/common/config";
export enum DiscordChannels {
trackedPlayerLogs = "1295985197262569512",
numberOneFeed = "1295988063817830430",
backendLogs = "1296524935237468250",
}
2024-10-25 17:44:19 +01:00
const client = new Client({
intents: [],
presence: {
status: "online",
activities: [
{
name: "scores...",
type: ActivityType.Watching,
url: "https://ssr.fascinated.cc",
},
],
},
});
2024-10-25 17:44:19 +01:00
client.once("ready", () => {
console.log("Discord bot ready!");
});
2024-10-25 17:44:19 +01:00
export async function initDiscordBot() {
console.log("Initializing discord bot...");
2024-10-25 17:44:19 +01:00
client.once("ready", async () => {
await client.initApplicationCommands();
});
2024-10-25 17:44:19 +01:00
await client.login(Config.discordBotToken!);
}
/**
* Logs the message to a discord channel.
*
* @param channelId the channel id to log to
* @param message the message to log
*/
2024-10-17 19:02:32 +01:00
export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) {
2024-10-25 17:44:19 +01:00
const channel = await client.channels.fetch(channelId);
if (channel == undefined) {
throw new Error(`Channel "${channelId}" not found`);
}
if (!channel.isSendable()) {
throw new Error(`Channel "${channelId}" is not sendable`);
}
channel.send({ embeds: [message] });
}