From ef838328198f22a4ac934a3da45ba73261acd0b6 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 17 Nov 2021 19:04:20 -0600 Subject: [PATCH] Added missing role and channel check --- Events/ready.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Events/ready.js b/Events/ready.js index 40eb74c..bbf436d 100644 --- a/Events/ready.js +++ b/Events/ready.js @@ -14,7 +14,7 @@ const panelconfig = yaml.load( const Event = require("../Structures/Event.js"); -module.exports = new Event("ready", (client) => { +module.exports = new Event("ready", async (client) => { client.user.setActivity(supportbot.BotActivity, { type: supportbot.ActivityType, url: supportbot.StreamingURL, @@ -65,7 +65,66 @@ module.exports = new Event("ready", (client) => { console.log(`\u001b[37m`, `SupportBot proudly created by Emerald Services`); console.log(` `); console.log(`\u001b[31m`, `――――――――――――――――――――――――――――――――――――――――――――`); + if ( + !supportbot.Guild || + (await client.guilds.cache.size) !== 1 || + (await client.guilds.cache.first().id) !== supportbot.Guild + ) { + console.log( + `\u001b[31m`, + `${client.user.username} is not in the correct server set in your config. Please join the server and restart the bot.` + ); + console.log(`\u001b[31m`, `${client.user.username} will now exit.`); + return process.exit(1); + } + const roles = [ + supportbot.Admin, + supportbot.Staff, + supportbot.TicketBlackListRole, + supportbot.DepartmentRole_1, + supportbot.DepartmentRole_2, + supportbot.DepartmentRole_3, + ]; + if (supportbot.AutoRole) roles.push(supportbot.AutoRole_Role); + const channels = [ + supportbot.SuggestionChannel, + supportbot.TicketLog, + supportbot.TranscriptLog, + panelconfig.Channel, + ]; + const missingR = []; + const missingC = []; + for (let c of channels) { + const find = await client.channels.cache.find( + (channel) => channel.name === c || channel.id === c + ); + if (!find) missingC.push(c); + } + for (let r of roles) { + const find = await client.guilds.cache + .first() + .roles.cache.find((role) => role.name === r || role.id === r); + if (!find) missingR.push(r); + } + + if (missingR.length > 0) { + console.log( + "\u001b[33m", + `[WARN] The following Roles could not be found! Please check your configs!\n${missingR.join( + ", " + )}` + ); + } + + if (missingC.length > 0) { + console.log( + "\u001b[33m", + `[WARN] The following Channels could not be found! Please check your configs!\n${missingC.join( + ", " + )}` + ); + } if (panelconfig.TicketPanel) { let chan1 = client.channels.cache.find( (channel) => channel.name === panelconfig.Channel