Files
commands
events
utils
bot.js
config.json
deploy-commands.js
package.json
README.md
Code
17 825
bot.js
const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages
],
partials: [Partials.Channel, Partials.Message]
});
client.commands = new Collection();
client.tickets = new Collection();
const commandFolders = fs.readdirSync('./commands');
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.data.name, command);
}
}
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
setInterval(() => {
const config = require('./config.json');
const now = Date.now();
const inactivityTime = config.ticketInactivityDays * 24 * 60 * 60 * 1000;
client.tickets.forEach((ticket, channelId) => {
if (now - ticket.lastActivity > inactivityTime) {
const channel = client.channels.cache.get(channelId);
if (channel) {
const { closeTicket } = require('./utils/ticketManager');
closeTicket(channel, client, 'Inactivity (3 days)');
}
}
});
}, 60 * 60 * 1000);
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
client.login(process.env.DISCORD_TOKEN);