|
1 | | -const { REST } = require("@discordjs/rest"), |
2 | | - { Routes } = require("discord-api-types/v9"), |
3 | | - Discord = require("discord.js"), |
4 | | - Utils = require("../Modules/Utils"), |
5 | | - packageJSON = require("../package.json"), |
6 | | - fsUtils = require("nodejs-fs-utils"), |
| 1 | +const { REST } = require("@discordjs/rest"), { Routes } = require("discord-api-types/v9"), |
| 2 | + Discord = require("discord.js"), Utils = require("../Modules/Utils"), |
| 3 | + packageJSON = require("../package.json"), fsUtils = require("nodejs-fs-utils"), |
7 | 4 | chalk = require("chalk"); |
| 5 | + |
8 | 6 | /** |
9 | 7 | * |
10 | 8 | * @param {Discord.Client} bot |
11 | 9 | * @param {Discord.Interaction} interaction |
12 | 10 | */ |
13 | 11 | module.exports = async (bot) => { |
14 | | - let { SlashCmds, SlashCmdsData, config } = bot; |
15 | | - |
16 | | - await Utils.logInfo( |
17 | | - "#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#" |
18 | | - ); |
19 | | - await Utils.logInfo( |
20 | | - " " |
21 | | - ); |
22 | | - await Utils.logInfo( |
23 | | - ` • ${chalk.bold( |
24 | | - `Brayan Bot v${packageJSON.version}` |
25 | | - )} is now Online! • ` |
26 | | - ); |
27 | | - await Utils.logInfo( |
28 | | - " " |
29 | | - ); |
30 | | - await Utils.logInfo( |
31 | | - " • Join our Discord Server for any Issues/Custom Bots • " |
32 | | - ); |
33 | | - await Utils.logInfo( |
34 | | - ` ${chalk.blue( |
35 | | - chalk.underline(`https://discord.gg/EgeZxGg6ev`) |
36 | | - )} ` |
37 | | - ); |
38 | | - await Utils.logInfo( |
39 | | - " " |
40 | | - ); |
41 | | - await Utils.logInfo( |
42 | | - "#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#" |
43 | | - ); |
44 | | - |
45 | | - let fSize = fsUtils.fsizeSync('./', { |
46 | | - skipErrors: true, |
47 | | - countFolders: true |
48 | | - }) |
| 12 | + let { SlashCmds, SlashCmdsData, config } = bot, |
| 13 | + rest = new REST({ version: "9" }).setToken(config.Settings.Token), |
| 14 | + fSize = fsUtils.fsizeSync('./', { |
| 15 | + skipErrors: true, |
| 16 | + countFolders: true |
| 17 | + }), guild = bot.guilds.cache.first(); |
49 | 18 |
|
| 19 | + await Utils.logInfo("#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#"); |
| 20 | + await Utils.logInfo(" "); |
| 21 | + await Utils.logInfo(` • ${chalk.bold(`Brayan Bot v${packageJSON.version}`)} is now Online! • `); |
| 22 | + await Utils.logInfo(" "); |
| 23 | + await Utils.logInfo(" • Join our Discord Server for any Issues/Custom Bots • "); |
| 24 | + await Utils.logInfo(` ${chalk.blue(chalk.underline(`https://discord.gg/EgeZxGg6ev`))} `); |
| 25 | + await Utils.logInfo(" "); |
| 26 | + await Utils.logInfo("#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#"); |
50 | 27 | await Utils.logInfo(`${chalk.bold(bot.Commands.size)} Command${bot.Commands.size == 1 ? "" : "s"} Loaded.`); |
51 | 28 | await Utils.logInfo(`${chalk.bold(bot.Events.length)} Event${bot.Events.length == 1 ? "" : "s"} Loaded.`); |
52 | | - const rest = new REST({ version: "9" }).setToken(config.Settings.Token); |
53 | | - SlashCmdsData = SlashCmdsData.filter((x) => typeof x == "object"); |
54 | | - try { |
55 | | - await rest.put( |
56 | | - Routes.applicationGuildCommands( |
57 | | - bot.user.id, |
58 | | - config.Settings.ServerID |
59 | | - ), |
60 | | - { |
61 | | - body: SlashCmdsData, |
| 29 | + |
| 30 | + await rest.put(Routes.applicationGuildCommands(bot.user.id, guild.id), { |
| 31 | + body: SlashCmdsData.filter((x) => typeof x == "object"), |
| 32 | + }).then(async registredCommands => { |
| 33 | + let fullPermissions = []; |
| 34 | + for (let index = 0; index < registredCommands.length; index++) { |
| 35 | + let element = registredCommands[index], |
| 36 | + commandYMLData = SlashCmds.find(x => x.name.toLowerCase() == element.name.toLowerCase()), |
| 37 | + cmdPerms = []; |
| 38 | + if (!commandYMLData.commandData.Permission.includes("@everyone")) { |
| 39 | + for (let i = 0; i < commandYMLData.commandData.Permission.length; i++) { |
| 40 | + const element2 = commandYMLData.commandData.Permission[i]; |
| 41 | + if (element2.toLowerCase() !== "@everyone") { |
| 42 | + let role = await Utils.findRole(element2, guild, true) |
| 43 | + if (role) { |
| 44 | + cmdPerms.push({ |
| 45 | + id: role.id, |
| 46 | + type: "ROLE", |
| 47 | + permission: true |
| 48 | + }) |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + fullPermissions.push({ |
| 53 | + id: element.id, |
| 54 | + permissions: cmdPerms |
| 55 | + }) |
| 56 | + } else { |
| 57 | + fullPermissions.push({ |
| 58 | + id: element.id, |
| 59 | + permissions: [ |
| 60 | + { |
| 61 | + id: guild.id, |
| 62 | + type: "ROLE", |
| 63 | + permission: true |
| 64 | + } |
| 65 | + ] |
| 66 | + }) |
62 | 67 | } |
63 | | - ); |
64 | | - await Utils.logInfo( |
65 | | - `${chalk.bold(SlashCmdsData.length)} Slash Command${SlashCmdsData.length == 1 ? "" : "s"} Loaded.` |
66 | | - ); |
67 | | - } catch (error) { |
68 | | - console.log(error); |
69 | | - Utils.logError(error); |
70 | | - } |
| 68 | + } |
| 69 | + await guild.commands.permissions.set({ fullPermissions }) |
| 70 | + await Utils.logInfo(`${chalk.bold(SlashCmdsData.length)} Slash Command${SlashCmdsData.length == 1 ? "" : "s"} Loaded.`); |
| 71 | + }).catch(e => { |
| 72 | + if (e.code == 50001) { |
| 73 | + Utils.logWarning(`[SlashCommands] \"${chalk.bold(`application.commands`)}\" scope wasn't selected while inviting the bot. Please use the below link to re-invite your bot.`) |
| 74 | + Utils.logWarning(`[SlashCommands] ${chalk.blue(chalk.underline(chalk.bold(`https://discord.com/api/oauth2/authorize?client_id=${bot.user.id}&permissions=8&scope=bot%20applications.commands`)))}`) |
| 75 | + } else { |
| 76 | + Utils.logError(e); |
| 77 | + } |
| 78 | + }) |
| 79 | + |
71 | 80 |
|
72 | 81 | await Utils.logInfo(`Logged in as: ${chalk.bold(bot.user.tag)}`); |
73 | 82 | await Utils.logInfo(`Currently using ${chalk.bold(Utils.bytesToSize(fSize))} of storage`); |
|
0 commit comments