🎨 Improve code readability by reformatting and updating function definitions and comments
This commit is contained in:
43
code/junk-drawer/discordbot-godispute/src/bot.js
Normal file
43
code/junk-drawer/discordbot-godispute/src/bot.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { Client, GatewayIntentBits } = require('discord.js');
|
||||
const { discordToken } = require('@config'); // Using alias for config
|
||||
const environment = process.env.NODE_ENV || 'development';
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent
|
||||
]
|
||||
});
|
||||
const serverDataFilePath = path.join(
|
||||
__dirname,
|
||||
`discord/store/${environment}-serverData.json`
|
||||
);
|
||||
|
||||
let serverData = {};
|
||||
if (fs.existsSync(serverDataFilePath)) {
|
||||
serverData = JSON.parse(fs.readFileSync(serverDataFilePath, 'utf8'));
|
||||
} else {
|
||||
fs.writeFileSync(serverDataFilePath, JSON.stringify({}, null, 2), 'utf8');
|
||||
console.warn(
|
||||
`Warning: File not found at ${serverDataFilePath}. Using empty server data.`
|
||||
);
|
||||
}
|
||||
|
||||
// Load event handlers
|
||||
const eventFiles = fs
|
||||
.readdirSync('./src/discord/events')
|
||||
.filter(file => file.endsWith('.js') && !file.endsWith('.spec.js'));
|
||||
for (const file of eventFiles) {
|
||||
const event = require(`./discord/events/${file}`);
|
||||
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args, serverData));
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute(...args, serverData));
|
||||
}
|
||||
}
|
||||
|
||||
client.login(discordToken);
|
||||
Reference in New Issue
Block a user