rewrite na js bo rust jest zjebany

This commit is contained in:
Patryk Koreń
2025-12-26 18:31:14 +01:00
parent 7b72b15caa
commit 375779de9c
23 changed files with 1259 additions and 3827 deletions

68
src/main.ts Normal file
View File

@@ -0,0 +1,68 @@
// Require the necessary discord.js classes
import { Client, Events, GatewayIntentBits, MessageFlags, REST, Routes } from 'discord.js';
import dotenv from 'dotenv';
import { commands } from "./commands";
import { createAudioPlayer } from '@discordjs/voice';
import { connectToChannel, playSong } from './util/helpers';
dotenv.config()
// AUDIO
export const player = createAudioPlayer();
// Create a new client instance
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates]
});
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, (readyClient) => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
registerCommands()
});
async function registerCommands() {
const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
const registry = Object.values(commands).map((cmd) => cmd.register().toJSON())
console.log(registry)
const data = await rest.put(Routes.applicationCommands(
process.env.DISCORD_APP_ID!,
), {
body: registry
});
}
// Log in to Discord with your client's token
client.login(process.env.DISCORD_TOKEN!);
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const cmd = commands[interaction.commandName];
if (!cmd) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await cmd.execute(interaction)
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral,
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
flags: MessageFlags.Ephemeral,
});
}
}
})