Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection } = require(`discord.js`);
- const fs = require('fs');
- const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
- const prefix = '>';
- client.commands = new Collection();
- require('dotenv').config();
- const functions = fs.readdirSync("./src/functions").filter(file => file.endsWith(".js"));
- const eventFiles = fs.readdirSync("./src/events").filter(file => file.endsWith(".js"));
- const commandFolders = fs.readdirSync("./src/commands");
- const commandFiles = fs.readdirSync("./src/prefixcommands").filter(file => file.endsWith('.js'));
- for (const file of commandFiles) {
- const command = require(`./src/prefixcommands/${file}`);
- client.commands.set(command.name, command);
- }
- // Logic for the Prefix Commands
- client.on('messageCreate', (message) => {
- if (!message.content.startsWith(prefix) || message.author.bot) return;
- const args = message.content.slice(prefix.length).split(/ +/);
- const commandName = args.shift().toLowerCase();
- const command = client.commands.get(commandName);
- if (!command) return;
- try {
- command.execute(message, args);
- } catch (error) {
- console.error(error);
- message.channel.send('There was an error while executing this command.');
- }
- });
- (async () => {
- for (file of functions) {
- require(`./functions/${file}`)(client);
- }
- client.handleEvents(eventFiles, "./src/events");
- client.handleCommands(commandFolders, "./src/commands");
- client.login(process.env.token)
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement