// Stable: https://discord.com/oauth2/authorize?client_id=928695013083316295&scope=bot%20applications.commands&permissions=0 // Beta: https://discord.com/oauth2/authorize?client_id=929057534491361341&scope=bot%20applications.commands&permissions=0 console.log("Channel: " + (require('fs').existsSync("./beta") ? "beta" : "stable")); global.channel = (require('fs').existsSync("./beta") ? "beta" : "stable"); const fs = require('fs'); const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9'); if (!fs.existsSync("./user/userdata.json")) fs.writeFileSync("./user/userdata.json", "{}"); if (!fs.existsSync("./user/spoilers.json")) fs.writeFileSync("./user/spoilers.json", "{}"); if (!fs.existsSync("./user/servers.json")) fs.writeFileSync("./user/servers.json", "{}"); if (!fs.existsSync("./reports")) fs.mkdirSync("./reports"); const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./config/token." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString()); const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js'); global.client = new Client({ intents: [Intents.FLAGS.GUILDS] }); const commandHandler = require('./handler/command'); const buttonHandler = require('./handler/button'); const menuHandler = require('./handler/menu'); const errorHandler = require('./handler/errors'); global.langs = JSON.parse(fs.readFileSync("./user/userdata.json")); global.spoils = JSON.parse(fs.readFileSync("./user/spoilers.json")); global.servers = JSON.parse(fs.readFileSync("./user/servers.json")); global.cooldowns = {}; global.l = (en, fr, id, gid) => { if (typeof servers[gid] !== "undefined") { if (servers[gid] === "fr") { return fr; } else { return en; } } else { if (langs[id] === "fr") { return fr; } else { return en; } } } const commands = require('./modules/registers'); client.on('ready', async () => { client.user.setActivity("/help", { type: "LISTENING" }) console.log(`Logged in as ${client.user.tag}!`); console.log("Started refreshing application (/) commands globally"); await rest.put( Routes.applicationCommands(fs.readFileSync("./config/client." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString()), { body: commands }, ); console.log("Successfully reloaded application (/) commands globally"); }); client.on('interactionCreate', async interaction => { if (!interaction) { return; } try { if (interaction.isCommand()) { await commandHandler(interaction); } else if (interaction.isButton()) { await buttonHandler(interaction); } else if (interaction.isSelectMenu()) { await menuHandler(interaction); } else { throw new Error("Interaction type not supported") } } catch (e) { errorHandler(interaction, e) } }); client.login(fs.readFileSync("./config/token." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString());