Files
Events
handlers
settings
slashCommands
giveaways.json
index.js
package.json
Code
40 2,560
index.js
const {
Client,
Collection,
GatewayIntentBits,
Partials,
ActivityType
} = require("discord.js");
const { GiveawaysManager } = require('discord-giveaways');
const chalk = require("chalk");
const config = require("./settings/config.json");
require('dotenv').config();
// Create Discord Client with proper intents
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution
],
partials: [
Partials.Message,
Partials.Channel,
Partials.GuildMember,
Partials.Reaction,
Partials.GuildScheduledEvent,
Partials.User,
Partials.ThreadMember
],
allowedMentions: {
parse: ['users', 'roles'],
repliedUser: true
},
rest: {
timeout: 60000
}
});
// Export client globally
module.exports = client;
// Initialize Collections
client.slashCommands = new Collection();
client.events = new Collection();
client.cooldowns = new Collection();
client.components = new Collection();
// Giveaways Manager Setup
const giveawayManager = new GiveawaysManager(client, {
storage: './giveaways.json',
default: {
botsCanWin: false,
embedColor: config.color,
embedColorEnd: config.color,
reaction: config.giveaway_react
}
});
client.giveawaysManager = giveawayManager;
// Load Handlers
console.log(chalk.cyan.bold('\n╔════════════════════════════════════════════════════════════╗'));
console.log(chalk.cyan.bold('║ InstantHC Bot - Discord.js v14 ║'));
console.log(chalk.cyan.bold('╚════════════════════════════════════════════════════════════╝\n'));
const handlers = ['event_handler', 'slash_handler', 'component_handler'];
handlers.forEach(handler => {
try {
require(`./handlers/${handler}`)(client);
console.log(chalk.green(`✓ Załadowano: ${handler}`));
} catch (error) {
console.error(chalk.red(`✗ Błąd ładowania ${handler}:`), error);
}
});
// Global Error Handlers
process.on('unhandledRejection', (error) => {
console.error(chalk.red.bold('[UNHANDLED REJECTION]'), error);
});
process.on('uncaughtException', (error) => {
console.error(chalk.red.bold('[UNCAUGHT EXCEPTION]'), error);
});
// Anti-Crash System
client.on('error', error => {
console.error(chalk.red.bold('[CLIENT ERROR]'), error);
});
client.on('warn', info => {
console.warn(chalk.yellow.bold('[CLIENT WARNING]'), info);
});
// Login
const token = process.env.DISCORD_TOKEN;
if (!token) {
console.error(chalk.red.bold('[ERROR] Brak tokena w pliku .env!'));
console.log(chalk.yellow('Dodaj token do pliku .env jako DISCORD_TOKEN=twój_token'));
process.exit(1);
}
client.login(token)
.then(() => {
console.log(chalk.green.bold('\n[✓] Bot zalogowany pomyślnie!\n'));
})
.catch(error => {
console.error(chalk.red.bold('[ERROR] Nie można zalogować bota:'));
console.error(chalk.red(error.message));
console.log(chalk.yellow('\nSprawdź czy:'));
console.log(chalk.yellow('1. Token w .env jest poprawny'));
console.log(chalk.yellow('2. Bot ma włączone wszystkie intenty w Developer Portal'));
console.log(chalk.yellow('3. Aplikacja ma dostęp do internetu\n'));
process.exit(1);
});