diff --git a/projects/backend/src/bot/bot.ts b/projects/backend/src/bot/bot.ts index e97ef15..0a4e8ad 100644 --- a/projects/backend/src/bot/bot.ts +++ b/projects/backend/src/bot/bot.ts @@ -8,7 +8,7 @@ export enum DiscordChannels { backendLogs = "1296524935237468250", } -const DiscordBot = new Client({ +const client = new Client({ intents: [], presence: { status: "online", @@ -23,16 +23,17 @@ const DiscordBot = new Client({ }, }); -DiscordBot.once("ready", () => { +client.once("ready", () => { console.log("Discord bot ready!"); }); -export function initDiscordBot() { +export async function initDiscordBot() { console.log("Initializing discord bot..."); - MetadataStorage.instance.build().then(async () => { - await DiscordBot.login(Config.discordBotToken!).then(); + client.once("ready", async () => { + await client.initApplicationCommands(); }); + await client.login(Config.discordBotToken!); } /** @@ -42,7 +43,7 @@ export function initDiscordBot() { * @param message the message to log */ export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) { - const channel = await DiscordBot.channels.fetch(channelId); + const channel = await client.channels.fetch(channelId); if (channel == undefined) { throw new Error(`Channel "${channelId}" not found`); } diff --git a/projects/backend/src/bot/command/refresh-player-scores-command.ts b/projects/backend/src/bot/command/refresh-player-scores-command.ts new file mode 100644 index 0000000..dee2d49 --- /dev/null +++ b/projects/backend/src/bot/command/refresh-player-scores-command.ts @@ -0,0 +1,18 @@ +import { Discord, Slash } from "discordx"; +import { CommandInteraction } from "discord.js"; +import { PlayerService } from "../../service/player.service"; + +@Discord() +export class RefreshPlayerScoresCommand { + @Slash({ + description: "Refreshes scores for all tracked players", + name: "refresh-player-scores", + defaultMemberPermissions: ["Administrator"], + }) + hello(interaction: CommandInteraction) { + interaction.reply("Updating player scores...").then(async response => { + await PlayerService.refreshPlayerScores(); + await response.edit("Done!"); + }); + } +}