2024-10-25 16:49:38 +00:00
|
|
|
import { Client } from "discordx";
|
2024-10-17 18:29:30 +01:00
|
|
|
import { ActivityType, EmbedBuilder } from "discord.js";
|
2024-10-22 15:59:41 +01:00
|
|
|
import { Config } from "@ssr/common/config";
|
2024-10-17 18:29:30 +01:00
|
|
|
|
|
|
|
export enum DiscordChannels {
|
|
|
|
trackedPlayerLogs = "1295985197262569512",
|
|
|
|
numberOneFeed = "1295988063817830430",
|
|
|
|
backendLogs = "1296524935237468250",
|
|
|
|
}
|
|
|
|
|
2024-10-25 17:44:19 +01:00
|
|
|
const client = new Client({
|
2024-10-17 18:29:30 +01:00
|
|
|
intents: [],
|
|
|
|
presence: {
|
|
|
|
status: "online",
|
2024-10-22 15:59:41 +01:00
|
|
|
|
2024-10-17 18:29:30 +01:00
|
|
|
activities: [
|
|
|
|
{
|
|
|
|
name: "scores...",
|
|
|
|
type: ActivityType.Watching,
|
|
|
|
url: "https://ssr.fascinated.cc",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-10-25 17:44:19 +01:00
|
|
|
client.once("ready", () => {
|
2024-10-17 18:29:30 +01:00
|
|
|
console.log("Discord bot ready!");
|
|
|
|
});
|
|
|
|
|
2024-10-25 17:44:19 +01:00
|
|
|
export async function initDiscordBot() {
|
2024-10-17 18:29:30 +01:00
|
|
|
console.log("Initializing discord bot...");
|
|
|
|
|
2024-10-25 18:00:15 +01:00
|
|
|
// Setup slash commands
|
2024-10-25 17:44:19 +01:00
|
|
|
client.once("ready", async () => {
|
|
|
|
await client.initApplicationCommands();
|
2024-10-17 18:29:30 +01:00
|
|
|
});
|
2024-10-25 18:00:15 +01:00
|
|
|
client.on("interactionCreate", interaction => {
|
|
|
|
client.executeInteraction(interaction);
|
|
|
|
});
|
|
|
|
|
2024-10-25 17:44:19 +01:00
|
|
|
await client.login(Config.discordBotToken!);
|
2024-10-17 18:29:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2024-10-17 18:29:30 +01:00
|
|
|
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] });
|
|
|
|
}
|