add bot cmd
Some checks failed
Deploy Backend / docker (ubuntu-latest) (push) Failing after 30s

This commit is contained in:
Lee 2024-10-25 17:44:19 +01:00
parent 53e0ce007d
commit 90b0994524
2 changed files with 25 additions and 6 deletions

@ -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`);
}

@ -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!");
});
}
}