DeltaBravo92

index.js

Aug 11th, 2022
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const client = new Discord.Client({intents: Object.values(Discord.IntentsBitField.Flags)})
  3. const { Collection, Client, MessageEmbed } = require("discord.js");
  4.  
  5. module.exports = {
  6.     client: client
  7. };
  8.  
  9. module.imports = {
  10.     getLogSymbols: './nodes_modules/log-symbols/index.js',
  11.     logSymbols: getLogSymbols
  12. };
  13. const { Manager } = require("lavacord");
  14. const { readdirSync } = require("fs");
  15. const { BOT_TOKEN, EMBED_COLOR, MUTE_ROLE, YT_API_KEY, COMMAND_PREFIX, STATS } = require("./settings/configuration").BOT_SETTINGS;
  16. const db = require('quick.db')
  17. const path = require("path");
  18. const Enmap = require('enmap');
  19. const Tickets = new Enmap({ name: 'tickets' });
  20. const i18n = require('i18n');
  21. if (!COMMAND_PREFIX) throw new Error('Please provide a prefix in the configuration')
  22. if (!BOT_TOKEN) throw new Error('Please provide a valid bot token to start the bot\nObtain one from here https://discord.com/developers/applications')
  23. if (!YT_API_KEY) throw new Error('Please provide a Youtube API key in the configuration.\nGet one here https://developers.google.com/youtube/v3/getting-started')
  24. if (!EMBED_COLOR) throw new Error('Please provide an embed hex color in the configuration. E.g. RED or #fl92jd')
  25. console.log(logSymbols.success, 'Finished successfully!');
  26. client.StickyMessages = new db.table(`sticky`)
  27. const StickyMessages = new db.table(`sticky`)
  28. client.db = require('quick.db')
  29. client.embed = class Embed extends MessageEmbed { color = EMBED_COLOR }
  30. client.on('ready', () => {
  31.     console.log(`Logged in as ${client.user.tag}!`);
  32.     client.user.setActivity(`everyone and -thing`, {
  33.         type: "Monitoring"
  34.     })
  35. });
  36. client.on('error', (e) => {
  37.     console.log(e)
  38. })
  39. client.on('warn', (e) => {
  40.     console.log(e)
  41. })
  42. client.on('debug', (e) => {
  43.     console.log(e)
  44. })
  45. process.on('unhandledRejection', (error) => {
  46.     console.log('Unhandled promise rejection:', error)
  47. })
  48.  
  49. i18n.configure({
  50.   locales: ["en", "ko", "fr", "pt_br", "zh_cn", "zh_tw"],
  51.   directory: path.join(__dirname, "locales"),
  52.   defaultLocale: "en",
  53.   objectNotation: true,
  54.   register: global,
  55.   logErrorFn: function (msg) {
  56.     console.log("error", msg);
  57.   },
  58.   missingKeyFn: function (locale, value) {
  59.     return value;
  60.   },
  61.   mustacheConfig: {
  62.     tags: ["{{", "}}"],
  63.     disable: false
  64.   }
  65. });
  66. client.tickets = Tickets;
  67. client.snipes = new Collection()
  68. client.commands = new Collection();
  69. client.color = EMBED_COLOR;
  70. client.muteRole = MUTE_ROLE;
  71. client.afk = new Collection()
  72. client.spam = new Collection()
  73. client.handle = require("./functions/handle");
  74. client.play = require("./functions/play");
  75. client.queue = new Collection()
  76. client.categories = new Collection()
  77. client.db = {
  78.     ...require('quick.db'),
  79.     ensure: (key, def) => {
  80.         if (db.get(key)) return db.get(key)
  81.         db.set(key, def)
  82.         return db.get(key, def)
  83.     }
  84. }
  85. client.manager = new Manager(client, [{ id: 'main', host: 'localhost', port: 2333, password: 'brandon2511' }])
  86. client.manager.on('ready', node => console.log(`Node ${node.id} is ready!`))
  87.     .on('disconnect', (ws, node) => console.log(`Node ${node.id} disconnected.`))
  88.     .on('reconnecting', node => console.log(`Node ${node.id} tries to reconnect.`))
  89.     .on('error', (error, node) => console.log(`Node ${node.id} got an error: ${error.message}`))
  90.  
  91. const eventFiles = readdirSync("./events").filter(f => f.endsWith(".js"));
  92. for (const file of eventFiles) {
  93.     const event = require(`./events/${file}`);
  94.     if (event.name) {
  95.         client.on(event.name, (...args) => event.execute(client, ...args));
  96.         console.log(`[√] Event ${file} has been successfully loaded!`);
  97.     }
  98. }
  99. const categories = ['fun', 'info', 'moderation', 'system', 'tickets', 'basic', 'music'];
  100. categories.forEach(async category => {
  101.     const commandFiles = readdirSync(`./commands/${category}`).filter(f => f.endsWith(".js"));
  102.     if (category !== 'owner') client.categories.set(category, commandFiles.map(s => s.split('.')[0]))
  103.     for (const file of commandFiles) {
  104.         try {
  105.             const command = require(`./commands/${category}/${file}`);
  106.             if (command.config) {
  107.                 client.commands.set(file.split('.')[0], { name: file.split('.')[0], ...command });
  108.                 console.log(`[√] Command ${file.split('.')[0]} has been successfully loaded!`);
  109.             } else throw new Error('Command missing config')
  110.         } catch (e) {
  111.             console.log(`[❌] Command ${file} failed to load: ${e.message}`)
  112.         }  
  113.     }
  114. })
  115. client.login(BOT_TOKEN).catch(() => {
  116.     console.log(
  117.         `[❌] Error while trying bot to log in.
  118.    [⚠️ POSSIBLE FIX] You provided an invalid token of the bot`
  119.     )
  120. })
Advertisement
Add Comment
Please, Sign In to add comment