index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const fs = require('node:fs');
  2. const path = require('node:path');
  3. const { Client, Events, Collection, GatewayIntentBits } = require('discord.js');
  4. const { token } = require('./config.json');
  5. const client = new Client({ intents: [GatewayIntentBits.Guilds] });
  6. // EVENTS HANDLER
  7. const eventsPath = path.join(__dirname, 'events');
  8. const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
  9. for (const file of eventFiles) {
  10. const filePath = path.join(eventsPath, file);
  11. const event = require(filePath);
  12. if (event.once) {
  13. client.once(event.name, (...args) => event.execute(...args));
  14. } else {
  15. client.on(event.name, (...args) => event.execute(...args));
  16. }
  17. }
  18. // COMMANDS HANDLER
  19. client.commands = new Collection();
  20. const commandsPath = path.join(__dirname, 'commands');
  21. const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
  22. for (const file of commandFiles) {
  23. const filePath = path.join(commandsPath, file);
  24. const command = require(filePath);
  25. if ('data' in command && 'execute' in command) {
  26. client.commands.set(command.data.name, command);
  27. } else {
  28. console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
  29. }
  30. }
  31. //LOGIN
  32. client.login(token);
  33. //WEB SERVER
  34. // var http = require('http');
  35. // http.createServer(function (req, res) {
  36. // res.write("I'm alive");
  37. // res.end();
  38. // }).listen(8080);