|
| 1 | +/** |
| 2 | + * @INFO |
| 3 | + * Loading all needed File Information Parameters |
| 4 | +*/ |
| 5 | +const config = require("../../botconfig/config.json"); //loading config file with token and prefix, and settings |
| 6 | +const ee = require("../../botconfig/embed.json"); //Loading all embed settings like color footertext and icon ... |
| 7 | +const Discord = require("discord.js"); //this is the official discord.js wrapper for the Discord Api, which we use! |
| 8 | +const { createBar, format, databasing, escapeRegex, isrequestchannel, getRandomInt, delay} = require("../../handlers/functions"); //Loading all needed functions |
| 9 | +const requestcmd = require("../../handlers/requestcmds"); |
| 10 | +//here the event starts |
| 11 | +module.exports = async (client, message) => { |
| 12 | + try { |
| 13 | + //if the message is not in a guild (aka in dms), return aka ignore the inputs |
| 14 | + if (!message.guild) return; |
| 15 | + //if the channel is on partial fetch it |
| 16 | + if (message.channel.partial) await message.channel.fetch(); |
| 17 | + //if the message is on partial fetch it |
| 18 | + if (message.partial) await message.fetch(); |
| 19 | + //ensure all databases for this server/user from the databasing function |
| 20 | + databasing(client, message.guild.id, message.author.id) |
| 21 | + //get the setup channel from the database and if its in there sent then do this |
| 22 | + if(isrequestchannel(client, message)) return requestcmd(client, message); //requestcommands |
| 23 | + // if the message author is a bot, return aka ignore the inputs |
| 24 | + if (message.author.bot) return; |
| 25 | + //get the current prefix from the database |
| 26 | + let prefix = client.settings.get(message.guild.id, "prefix"); |
| 27 | + //if not in the database for some reason use the default prefix |
| 28 | + if (prefix === null) prefix = config.prefix; |
| 29 | + //the prefix can be a Mention of the Bot / The defined Prefix of the Bot |
| 30 | + const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`); |
| 31 | + //if its not that then return |
| 32 | + if (!prefixRegex.test(message.content)) return; |
| 33 | + //now define the right prefix either ping or not ping |
| 34 | + const [, matchedPrefix] = message.content.match(prefixRegex); |
| 35 | + //CHECK IF IN A BOT CHANNEL OR NOT |
| 36 | + if(client.settings.get(message.guild.id, `botchannel`).toString() !== ""){ |
| 37 | + //if its not in a BotChannel, and user not an ADMINISTRATOR |
| 38 | + if (!client.settings.get(message.guild.id, `botchannel`).includes(message.channel.id) && !message.member.hasPermission("ADMINISTRATOR")) { |
| 39 | + //create the info string |
| 40 | + let leftb = ""; |
| 41 | + for(let i = 0; i < client.settings.get(message.guild.id, `botchannel`).length; i++){ |
| 42 | + leftb +="<#" +client.settings.get(message.guild.id, `botchannel`)[i] + "> / " |
| 43 | + } |
| 44 | + //send informational message |
| 45 | + try{ message.react("❌"); }catch{} |
| 46 | + return message.channel.send(new Discord.MessageEmbed() |
| 47 | + .setColor(ee.wrongcolor) |
| 48 | + .setFooter(ee.footertext, ee.footericon) |
| 49 | + .setTitle(`❌ Error | Not in the Bot Chat!`) |
| 50 | + .setDescription(`There is a Bot chat setup in this GUILD! try using the Bot Commands here:\n> ${leftb.substr(0, leftb.length - 3)}`) |
| 51 | + ).then(async msg => { |
| 52 | + try{ |
| 53 | + await delay(5000) |
| 54 | + if(msg && message.channel.messages.cache.get(msg.id)) msg.delete(); |
| 55 | + }catch{ /* */ } |
| 56 | + }); |
| 57 | + } |
| 58 | + } |
| 59 | + //create the arguments with sliceing of of the rightprefix length |
| 60 | + const args = message.content.slice(matchedPrefix.length).trim().split(/ +/); |
| 61 | + //creating the cmd argument by shifting the args by 1 |
| 62 | + const cmd = args.shift().toLowerCase(); |
| 63 | + //if no cmd added return error |
| 64 | + if (cmd.length === 0){ |
| 65 | + if(matchedPrefix.includes(client.user.id)) |
| 66 | + return message.channel.send(new Discord.MessageEmbed() |
| 67 | + .setColor(ee.color) |
| 68 | + .setFooter(ee.footertext,ee.footericon) |
| 69 | + .setTitle(`Hugh? I got pinged? Imma give you some help`) |
| 70 | + .setDescription(`To see all Commands type: \`${prefix}help\`\n\nTo setup a Unique Song Request System type \`${prefix}setup\`\n\nOther then that, start listening to some music with \`${prefix}play <Song/Url>\``) |
| 71 | + ); |
| 72 | + return; |
| 73 | + } |
| 74 | + //get the command from the collection |
| 75 | + let command = client.commands.get(cmd); |
| 76 | + //if the command does not exist, try to get it by his alias |
| 77 | + if (!command) command = client.commands.get(client.aliases.get(cmd)); |
| 78 | + //if the command is now valid |
| 79 | + if (command){ |
| 80 | + if (!client.cooldowns.has(command.name)) { //if its not in the cooldown, set it too there |
| 81 | + client.cooldowns.set(command.name, new Discord.Collection()); |
| 82 | + } |
| 83 | + const now = Date.now(); //get the current time |
| 84 | + const timestamps = client.cooldowns.get(command.name); //get the timestamp of the last used commands |
| 85 | + const cooldownAmount = (command.cooldown || 1) * 1000; //get the cooldownamount of the command, if there is no cooldown there will be automatically 1 sec cooldown, so you cannot spam it^^ |
| 86 | + if (timestamps.has(message.author.id)) { //if the user is on cooldown |
| 87 | + const expirationTime = timestamps.get(message.author.id) + cooldownAmount; //get the amount of time he needs to wait until he can run the cmd again |
| 88 | + if (now < expirationTime) { //if he is still on cooldonw |
| 89 | + const timeLeft = (expirationTime - now) / 1000; //get the lefttime |
| 90 | + try{ message.react("❌"); }catch{} |
| 91 | + return message.channel.send(new Discord.MessageEmbed() |
| 92 | + .setColor(ee.wrongcolor) |
| 93 | + .setFooter(ee.footertext,ee.footericon) |
| 94 | + .setTitle(`❌ Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`) |
| 95 | + .addField("Why a delay?", "Because that's the only way how I can prevent you from abusing(spamming) me!") |
| 96 | + ); //send an information message |
| 97 | + } |
| 98 | + } |
| 99 | + timestamps.set(message.author.id, now); //if he is not on cooldown, set it to the cooldown |
| 100 | + setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); //set a timeout function with the cooldown, so it gets deleted later on again |
| 101 | + try{ |
| 102 | + client.stats.inc(message.guild.id, "commands"); //counting our Database stats for SERVER |
| 103 | + client.stats.inc("global", "commands"); //counting our Database Stats for GLOBAL |
| 104 | + //if Command has specific permission return error |
| 105 | + if(command.memberpermissions) { |
| 106 | + if (!message.member.hasPermission(command.memberpermissions)) { |
| 107 | + try{ message.react("❌"); }catch{} |
| 108 | + message.channel.send(new Discord.MessageEmbed() |
| 109 | + .setColor(ee.wrongcolor) |
| 110 | + .setFooter(ee.footertext, ee.footericon) |
| 111 | + .setTitle("❌ Error | You are not allowed to run this command!") |
| 112 | + .setDescription(`You need these Permissions: \`${command.memberpermissions.join("`, ``")}\``) |
| 113 | + ).then(async msg => { |
| 114 | + try{ |
| 115 | + await delay(5000) |
| 116 | + if(msg && message.channel.messages.cache.get(msg.id)) msg.delete(); |
| 117 | + }catch{ /* */ } |
| 118 | + }); |
| 119 | + throw { |
| 120 | + message: "❌ Error | You are not allowed to run this command!" + `You need these Permissions: \`${command.memberpermissions.join("`, ``")}\`` |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + //if Command has specific permission return error |
| 125 | + if(client.settings.get(message.guild.id, `djonlycmds`).join(" ").toLowerCase().split(" ").includes(command.name.toLowerCase())) { |
| 126 | + //Check if there is a Dj Setup |
| 127 | + if(client.settings.get(message.guild.id, `djroles`).toString()!==""){ |
| 128 | + const player = client.manager.players.get(message.guild.id); |
| 129 | + //create the string of all djs and if he is a dj then set it to true |
| 130 | + let isdj=false; |
| 131 | + let leftb = ""; |
| 132 | + if(client.settings.get(message.guild.id, `djroles`).join("") === "") |
| 133 | + leftb = "no Dj Roles, aka all Users are Djs" |
| 134 | + else |
| 135 | + for(let i = 0; i < client.settings.get(message.guild.id, `djroles`).length; i++){ |
| 136 | + if(message.member.roles.cache.has(client.settings.get(message.guild.id, `djroles`)[i])) isdj = true; |
| 137 | + if(!message.guild.roles.cache.get(client.settings.get(message.guild.id, `djroles`)[i])) continue; |
| 138 | + leftb += "<@&" + client.settings.get(message.guild.id, `djroles`)[i] + "> | " |
| 139 | + } |
| 140 | + //if not a DJ and not a nAdmin |
| 141 | + |
| 142 | + if(!isdj && !message.member.hasPermission("ADMINISTRATOR")) { |
| 143 | + if(player && player.queue.current.requester.id !== message.author.id) { |
| 144 | + try{ message.react("❌"); }catch{} |
| 145 | + return message.channel.send(new Discord.MessageEmbed() |
| 146 | + .setColor(ee.wrongcolor) |
| 147 | + .setFooter(ee.footertext, ee.footericon) |
| 148 | + .setTitle("❌ Error | You are not allowed to run this command!") |
| 149 | + .setDescription(`You need to have one of those Roles:\n${leftb.substr(0, leftb.length-3)}\n\nOr be the Requester (${player.queue.current.requester}) of the current Track!`) |
| 150 | + ).then(async msg => { |
| 151 | + try{ |
| 152 | + await delay(5000) |
| 153 | + if(msg && message.channel.messages.cache.get(msg.id)) msg.delete(); |
| 154 | + }catch{ /* */ } |
| 155 | + }); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + //if there is a SETUP with an EXISTING text channel and its a MUSIC or FILTER COMMAND AND NOT in the RIGHT CHANNEL return error msg and if its request only enabled |
| 161 | + if(message.guild.channels.cache.get(client.setups.get(message.guild.id, "textchannel")) && |
| 162 | + (command.category.toLowerCase().includes("music") || command.category.toLowerCase().includes("filter")) && |
| 163 | + client.setups.get(message.guild.id, "textchannel") !== message.channel.id && |
| 164 | + client.settings.get(message.guild.id, `requestonly`)){ |
| 165 | + try{ message.react("❌"); }catch{} |
| 166 | + return message.channel.send(new Discord.MessageEmbed() |
| 167 | + .setColor(ee.wrongcolor) |
| 168 | + .setFooter(ee.footertext, ee.footericon) |
| 169 | + .setTitle("❌ Error | You are not allowed to run this Command here!") |
| 170 | + .setDescription(`Please run it in: ${message.guild.channels.cache.get(client.setups.get(message.guild.id, "textchannel"))} | To enable that you can use the Command anywhere type: \`${prefix}togglerequestonly\``) |
| 171 | + ) |
| 172 | + |
| 173 | + } |
| 174 | + //if the Bot has not enough permissions return error |
| 175 | + if(!message.guild.me.hasPermission("ADMINISTRATOR")){ |
| 176 | + try{ message.react("❌"); }catch{} |
| 177 | + return message.channel.send(new Discord.MessageEmbed() |
| 178 | + .setColor(ee.wrongcolor) |
| 179 | + .setFooter(ee.footertext, ee.footericon) |
| 180 | + .setTitle("❌ Error | I don't have enough Permissions!") |
| 181 | + .setDescription("Please give me ADMINISTRATOR, because i need it to delete Messages, Create Channel and execute all Admin Commands ") |
| 182 | + ) |
| 183 | + } |
| 184 | + //try to delete the message of the user who ran the cmd |
| 185 | + //try{ message.delete(); }catch{} |
| 186 | + |
| 187 | + //react with an random emoji, ... "random" |
| 188 | + //let emojis = ["👌", "👌", "👌", "👍", "👍", "✅", "✅", "✅", "✌", "🎧", "❤", "✨"] |
| 189 | + //try{ message.react(emojis[getRandomInt(emojis.length)]); }catch{} |
| 190 | + |
| 191 | + //run the command with the parameters: client, message, args, user, text, prefix, |
| 192 | + command.run(client, message, args, message.member, args.join(" "), prefix); |
| 193 | + }catch (e) { |
| 194 | + console.log(String(e.stack).red) |
| 195 | + return message.channel.send(new Discord.MessageEmbed() |
| 196 | + .setColor(ee.wrongcolor) |
| 197 | + .setFooter(ee.footertext, ee.footericon) |
| 198 | + .setTitle("❌ Something went wrong while, running the: `" + command.name + "` command") |
| 199 | + .setDescription(`\`\`\`${e.message}\`\`\``) |
| 200 | + ).then(async msg => { |
| 201 | + try{ |
| 202 | + await delay(5000) |
| 203 | + if(msg && message.channel.messages.cache.get(msg.id)) msg.delete(); |
| 204 | + }catch{ /* */ } |
| 205 | + }); |
| 206 | + } |
| 207 | + } |
| 208 | + else //if the command is not found send an info msg |
| 209 | + return message.channel.send(new Discord.MessageEmbed() |
| 210 | + .setColor(ee.wrongcolor) |
| 211 | + .setFooter(ee.footertext, ee.footericon) |
| 212 | + .setTitle(`❌ Unkown command, try: **\`${prefix}help\`**`) |
| 213 | + .setDescription(`The prefix for this Guild is: \`${prefix}\`\nYou can also ping me, instead of using a Prefix!\n\nTo play Music simply type \`${prefix}play <Title / Url>\`\n\nTo create a unique Requesting Setup type \`${prefix}setup\``) |
| 214 | + ).then(async msg => { |
| 215 | + try{ |
| 216 | + await delay(5000) |
| 217 | + if(msg && message.channel.messages.cache.get(msg.id)) msg.delete(); |
| 218 | + }catch{ /* */ } |
| 219 | + }); |
| 220 | + }catch (e){ |
| 221 | + return message.channel.send(new MessageEmbed() |
| 222 | + .setColor("RED") |
| 223 | + .setTitle(`❌ ERROR | An error occurred`) |
| 224 | + .setDescription(`\`\`\`${e.stack}\`\`\``) |
| 225 | + ); |
| 226 | + } |
| 227 | +} |
| 228 | +/** |
| 229 | + * @INFO |
| 230 | + * Bot Coded by Tomato#6966 | https://github.com/Tomato6966/discord-js-lavalink-Music-Bot-erela-js |
| 231 | + * @INFO |
| 232 | + * Work for Milrato Development | https://milrato.eu |
| 233 | + * @INFO |
| 234 | + * Please mention Him / Milrato Development, when using this Code! |
| 235 | + * @INFO |
| 236 | +*/ |
0 commit comments