UNPKG

cruach

Version:

Command Handler Modüle For Discord Bots

127 lines (122 loc) 5.44 kB
const { Collection } = require("discord.js") const fs = require('fs') const chalk = require("chalk") const hata = chalk.red("> Hata! : ") const ads = chalk.red("İnstagram dan takip etmeyi unutmayın - ysteelx_official") const login = chalk.green("Bilgi: Bot Giriş Yaptı \n2117 Studio Created By YSteelX\n"+ads) const yüklendimsj = chalk.yellow("Komut(lar) yüklendi: ") //2117 module.exports = class { constructor(client,komuts,eventLoad, ownerID, options) { options = options || {yardımKomutu: false} if (!client) throw new ReferenceError(hata + "Client Belirtiniz") if (!komuts) throw new ReferenceError(hata + "Komutlar Klasörünü Belirtiniz") if (!ownerID) throw new ReferenceError(hata + "Owner İD Belirtiniz") //imports this.client= client; this.client.komuts = komuts this.komuts = komuts this.ownerID = ownerID //yüklendi fs.readdir(`${process.cwd()}/${eventLoad}`, (err, files) => { if (err) return console.error(err); files.forEach(file => { const event = require(`${process.cwd()}/${eventLoad}/${file}`); let eventName = file.split(".")[0]; client.on(eventName, event.bind(null, client)) }); }); console.log(login) console.log(yüklendimsj) client.commands=new Collection() client.aliases=new Map() var commandFiles = fs .readdirSync(`${process.cwd()}/${komuts}`) .filter(file => file.endsWith('.js')); for (var file of commandFiles) { var command = require(`${process.cwd()}/${komuts}/${file}`); console.log("Name: "+chalk.green(command.name)+" Aliases: "+chalk.magenta(command.aliases)) client.commands.set(command.name, command); if (command.aliases && Array.isArray(command.aliases)) command.aliases.forEach(alias => client.aliases.set(alias, command.name)); } if(options.owner) { var commandFiles2 = fs .readdirSync(`${process.cwd()}/node_modules/cruach/sahip`) .filter(file3 =>file3.endsWith('.js')); for (var file3 of commandFiles2) { var sahip = require(`${process.cwd()}/node_modules/cruach/sahip/${file3}`) client.commands.set(sahip.name,sahip) if (sahip.aliases && Array.isArray(sahip.aliases)) sahip.aliases.forEach(alias => client.aliases.set(alias, sahip.name)); } } if(options.ana) { var commandFiles3 = fs .readdirSync(`${process.cwd()}/node_modules/cruach/ana`) .filter(file0 =>file0.endsWith('.js')); for (var file0 of commandFiles3) { var ana = require(`${process.cwd()}/node_modules/cruach/ana/${file0}`) client.commands.set(ana.name,ana) if (ana.aliases && Array.isArray(ana.aliases)) ana.aliases.forEach(alias => client.aliases.set(alias, ana.name)); } } }// Woney Code - Woney + YSteelX - Zynp message(msg,prefix=".",options) { options = options || {answebots: false,prefixtoping: true,pingprefix: true, ystlife: false} if (!msg) throw new ReferenceError("Err") if (!options.answebots) { if (msg.author.bot) return; } let p=prefix if (options.pingprefix) { if (msg.content === `<@!${this.client.user.id}>`) return msg.channel.send(`Prefixim: **${p}**`) } if (options.prefixtoping) { if (msg.content.startsWith(`<@!${this.client.user.id}>`)) p=`<@!${this.client.user.id}>` } if (options.ystlife) { console.log(chalk.magenta('YSteelX = Zynp')) } if (msg.webhookID || msg.channel.type === "dm" || !msg.content || !msg.channel.guild) return; if (!msg.content.startsWith(p)) return; const komutadi = msg.content.slice(p.length).trim().split(' ')[0] const args = msg.content.slice(p.length).trim().split(' ').slice(1) const command = this.client.commands.get(komutadi) || this.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(komutadi)) if (!command) { return; }; if (command.ownerOnly) { if(this.ownerID[1] == undefined) { if ((this.ownerID[0]) !== msg.author.id) { return msg.reply("Bu Komut Sahiplerim İçindir!") } else { try { command.run(msg,args,this.client) } catch (e) { console.log(e) msg.channel.send(`Hata.Lütfen **${komutadi}** komutunda hata olduğunu sahiplerime bildiriniz.`) } } } else if(this.ownerID[1] !== undefined) { if(this.ownerID[0] == msg.author.id || this.ownerID[1] == msg.author.id) { try { command.run(msg,args,this.client) } catch (e) { console.log(e) msg.channel.send(`Hata.Lütfen **${komutadi}** komutunda hata olduğunu sahiplerime bildiriniz.`) } } else { return msg.reply("Bu Komut Sahiplerim İçindir!") } } } else { try { command.run(msg,args,this.client) } catch (e) { console.log(e) msg.channel.send(`Hata.Lütfen **${komutadi}** komutunda hata olduğunu sahiplerime bildiriniz`) } } } } //2117 Studio