Advertisement
Danulsan

Untitled

Jun 21st, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection } = require(`discord.js`);
  2. const fs = require('fs');
  3. const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
  4.  
  5. const prefix = '>';
  6.  
  7. client.commands = new Collection();
  8.  
  9. require('dotenv').config();
  10.  
  11. const functions = fs.readdirSync("./src/functions").filter(file => file.endsWith(".js"));
  12. const eventFiles = fs.readdirSync("./src/events").filter(file => file.endsWith(".js"));
  13. const commandFolders = fs.readdirSync("./src/commands");
  14. const commandFiles = fs.readdirSync("./src/prefixcommands").filter(file => file.endsWith('.js'));
  15.  
  16. for (const file of commandFiles) {
  17. const command = require(`./src/prefixcommands/${file}`);
  18. client.commands.set(command.name, command);
  19. }
  20.  
  21.  
  22. // Logic for the Prefix Commands
  23. client.on('messageCreate', (message) => {
  24. if (!message.content.startsWith(prefix) || message.author.bot) return;
  25.  
  26. const args = message.content.slice(prefix.length).split(/ +/);
  27. const commandName = args.shift().toLowerCase();
  28.  
  29. const command = client.commands.get(commandName);
  30.  
  31. if (!command) return;
  32.  
  33. try {
  34. command.execute(message, args);
  35. } catch (error) {
  36. console.error(error);
  37. message.channel.send('There was an error while executing this command.');
  38. }
  39. });
  40.  
  41.  
  42. (async () => {
  43. for (file of functions) {
  44. require(`./functions/${file}`)(client);
  45. }
  46. client.handleEvents(eventFiles, "./src/events");
  47. client.handleCommands(commandFolders, "./src/commands");
  48. client.login(process.env.token)
  49. })();
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement