diff options
author | Minteck <contact@minteck.org> | 2022-01-08 21:47:45 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-08 21:47:45 +0100 |
commit | be6c790e43be36cfa6669110c7064a67ad3c4623 (patch) | |
tree | 3e81dd5a8caaf3f9c9db6b21f858167f01983119 /index.js | |
parent | ac2dea4a23ca72001e41c1dbf66ff1a0d01e217c (diff) | |
download | ponyfind-be6c790e43be36cfa6669110c7064a67ad3c4623.tar.gz ponyfind-be6c790e43be36cfa6669110c7064a67ad3c4623.tar.bz2 ponyfind-be6c790e43be36cfa6669110c7064a67ad3c4623.zip |
Update
Diffstat (limited to 'index.js')
-rw-r--r--[-rwxr-xr-x] | index.js | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -1,26 +1,28 @@ -// Stable: https://discord.com/oauth2/authorize?client_id=928695013083316295&scope=bot%20applications.commands&permissions=8 -// Beta: https://discord.com/oauth2/authorize?client_id=929057534491361341&scope=bot%20applications.commands&permissions=8 +// 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: " + (typeof process.argv[2] !== "undefined" ? "beta" : "stable")); +global.channel = (typeof process.argv[2] !== "undefined" ? "beta" : "stable"); const fs = require('fs'); const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9'); -if (!fs.existsSync("./userdata.json")) fs.writeFileSync("./userdata.json", "{}"); -if (!fs.existsSync("./servers.json")) fs.writeFileSync("./servers.json", "{}"); +if (!fs.existsSync("./user/userdata.json")) fs.writeFileSync("./user/userdata.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("./token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString()); +const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./config/token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString()); const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js'); -const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); +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("./userdata.json")); -global.servers = JSON.parse(fs.readFileSync("./servers.json")); +global.langs = JSON.parse(fs.readFileSync("./user/userdata.json")); +global.servers = JSON.parse(fs.readFileSync("./user/servers.json")); global.l = (en, fr, id, gid) => { if (typeof servers[gid] !== "undefined") { @@ -38,7 +40,7 @@ global.l = (en, fr, id, gid) => { } } -const commands = require('./registers'); +const commands = require('./modules/registers'); client.on('ready', async () => { console.log(`Logged in as ${client.user.tag}!`); @@ -47,7 +49,7 @@ client.on('ready', async () => { console.log('Started refreshing application (/) commands for guild ' + guild + '.'); await rest.put( - Routes.applicationGuildCommands(fs.readFileSync("./client.txt").toString(), guild), + Routes.applicationGuildCommands(fs.readFileSync("./config/client." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString(), guild), { body: commands }, ); @@ -58,6 +60,23 @@ client.on('ready', async () => { } }); +client.on('guildCreate', async () => { + for (let guild of client.guilds.cache.map(g => g.id)) { + try { + console.log('Started refreshing application (/) commands for guild ' + guild + '.'); + + await rest.put( + Routes.applicationGuildCommands(fs.readFileSync("./config/client." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString(), guild), + { body: commands }, + ); + + console.log('Successfully reloaded application (/) commands for guild ' + guild + '.'); + } catch (error) { + console.error(error); + } + } +}) + client.on('interactionCreate', async interaction => { try { if (interaction.isCommand()) { @@ -74,4 +93,4 @@ client.on('interactionCreate', async interaction => { } }); -client.login(fs.readFileSync("./token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString());
\ No newline at end of file +client.login(fs.readFileSync("./config/token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString());
\ No newline at end of file |