Files
src
package.json
ИНСТРУКЦИЯ.md
Code
10 519
src/index.js
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates
]
});
client.commands = new Collection();
client.queues = new Map();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(path.join(commandsPath, file));
if (command.data && command.execute) {
client.commands.set(command.data.name, command);
}
}
client.once('ready', () => {
console.log(`✅ Logged in as ${client.user.tag}`);
client.user.setActivity('YouTube 🎬', { type: 3 });
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(`Error executing ${interaction.commandName}:`, error);
const msg = { content: '❌ An error occurred while executing this command.', ephemeral: true };
if (interaction.replied || interaction.deferred) {
await interaction.followUp(msg);
} else {
await interaction.reply(msg);
}
}
});
client.on('error', (error) => {
console.error('Discord client error:', error);
});
client.login(process.env.DISCORD_TOKEN);