Advertisement
Guest User

index.js

a guest
Apr 13th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const express = require("express");
  3. const app = express()
  4. const dotenv = require("dotenv");
  5. dotenv.config();
  6.  
  7. app.listen(3000, () => {
  8. console.log("project is running!");
  9. })
  10.  
  11. app.get("/", (req, res) => {
  12. res.send("Hello world!");
  13. })
  14.  
  15. const client = new Discord.Client({
  16. intents:
  17. ["GUILDS", "GUILD_MESSAGES"],
  18. allowedMentions: ["users"]
  19. });
  20. const fs = require("fs");
  21. const prefix = "~";
  22. client.commands = new Discord.Collection();
  23. const commands = fs.readdirSync("./Commands").filter(file => file.endsWith(".js"));
  24. for (file of commands) {
  25. const commandName = file.split(".")[0]
  26. const command = require(`./Commands/${commandName}`)
  27. client.commands.set(commandName, command)
  28. }
  29.  
  30. client.on("messageCreate", async message => {
  31. if (message.content.startsWith(prefix)) {
  32. const args = message.content.slice(prefix.length).trim().split(/ +/g)
  33. const commandName = args.shift()
  34. const command = client.commands.get(commandName)
  35. if (!command) return
  36. try {
  37. command.run(client, message, args, Discord)
  38. } catch (err) {
  39. message.channel.send(`There was an error while executing the command; Error: ${err}`)
  40. }
  41.  
  42.  
  43.  
  44. }
  45. })
  46.  
  47. client.login(process.env.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement