├── .gitattributes ├── Bot Sharder ├── README.md └── sharded-bot.js └── LICENSE.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | /.github export-ignore 4 | .editorconfig export-ignore 5 | .eslintrc.json export-ignore 6 | .gitignore export-ignore 7 | .prettierrc.json export-ignore 8 | .prettierignore export-ignore 9 | package-lock.json export-ignore 10 | package.json export-ignore 11 | -------------------------------------------------------------------------------- /Bot Sharder/README.md: -------------------------------------------------------------------------------- 1 | **NOTE: Do not use this unless your bot is in over 2000 guilds, there is no point if its below, it uses more resources, and will probably break commands that you already use** 2 | 3 | # DBM Bot Sharding 4 | 5 | Allows your bot created by Discord Bot Maker to take advantage of sharding! 6 | 7 | ## Installation 8 | 9 | Download the [ZIP file] and extract the file to your bot folder. 10 | 11 | Your Bot folder should look like this: 12 | 13 | ![shard](https://i.imgur.com/sHqbJjV.png) 14 | 15 | ## Running 16 | 17 | Open a Command Prompt window on the bot folder and run `node sharded-bot.js`. It should look somewhat similar to this: 18 | 19 | ![node](https://i.imgur.com/AKuzOrR.png) 20 | 21 | If you want to provide a different shard count, add `--shard_count=[number]` after `node sharded-bot.js`; ex. `node sharded-bot.js --shard_count=3`. 22 | The default `shard_count` flag is set to `auto` (determined by discord.js), which is fine for most bots. 23 | 24 | To change the bot startup file, add `--startup=./index.js` after `node sharded-bot.js`; ex. `node sharded-bot.js --startup=./index.js`. 25 | The default `startup` parameter is set to `bot.js`. 26 | 27 | **If you want to do anything across shards you will need to use** [`client.shard.broadcastEval()`] 28 | 29 | For more information in regards to sharding, check [this guide]. 30 | 31 | [zip file]: https://downgit.github.io/#/home?url=https://github.com/dbm-network/custom-files/blob/master/Bot%20Sharder/sharded-bot.js 32 | [this guide]: https://discordjs.guide/sharding/ 33 | [`client.shard.broadcasteval()`]: https://discord.js.org/#/docs/main/stable/class/ShardClientUtil?scrollTo=broadcastEval 34 | -------------------------------------------------------------------------------- /Bot Sharder/sharded-bot.js: -------------------------------------------------------------------------------- 1 | // Made by TheMonDon#1721 2 | // Some code by General Wrex 3 | const version = '1.1'; 4 | 5 | // Include discord.js and original check 6 | const { version: djsVersion, ShardingManager } = require('discord.js'); 7 | if (djsVersion < '12.0.0') { 8 | console.log( 9 | 'This version of Discord Bot Maker requires Discord.JS v12.\nPlease use "Project > Module Manager" and "Project > Reinstall Node Modules" to update to Discord.JS v12.', 10 | ); 11 | throw new Error('Need Discord.JS v12 to Run!!!'); 12 | } 13 | 14 | console.log('-'.repeat(50)); 15 | console.log("TheMonDon's DBM Bot Sharder"); 16 | console.log(`Version: ${version}`); 17 | console.log("You can change the amount of shards by providing '--shard_count=[number]' (default: auto)"); 18 | console.log("You can change the bot file by providing '--startup=./index.js' (default bot.js)"); 19 | console.log('-'.repeat(50)); 20 | 21 | let totalShards = 'auto'; 22 | let startup = './bot.js'; 23 | 24 | function getArgs() { 25 | const args = {}; 26 | process.argv.slice(2, process.argv.length).forEach((arg) => { 27 | if (arg.slice(0, 2) === '--') { 28 | const longArg = arg.split('='); 29 | const longArgFlag = longArg[0].slice(2, longArg[0].length); 30 | const longArgValue = longArg.length > 1 ? longArg[1] : true; 31 | args[longArgFlag] = longArgValue; 32 | } else if (arg[0] === '-') { 33 | const flags = arg.slice(1, arg.length).split(''); 34 | flags.forEach((flag) => { 35 | args[flag] = true; 36 | }); 37 | } 38 | }); 39 | return args; 40 | } 41 | 42 | const args = getArgs(); 43 | if (args && args.shard_count) { 44 | totalShards = parseInt(args.shard_count, 10); 45 | console.log(`Command Line Arg: shard_count=${totalShards}`); 46 | } 47 | if (args && args.startup) { 48 | startup = args.startup; 49 | console.log(`Command Line Arg: startup=${startup} (Bot File)`); 50 | } 51 | 52 | console.log(`Starting the DBM Bot with ${totalShards} total shards...`); 53 | 54 | // dbms' encryption system 55 | const crypto = require('crypto'); 56 | let password = ''; 57 | let token; 58 | 59 | try { 60 | password = require('discord-bot-maker'); 61 | } catch {} 62 | 63 | const decrypt = (text) => { 64 | if (password.length === 0) return text; 65 | const decipher = crypto.createDecipheriv('aes-128-ofb', password); 66 | let dec = decipher.update(text, 'hex', 'utf8'); 67 | dec += decipher.final('utf8'); 68 | return dec; 69 | }; 70 | 71 | const { existsSync, readFileSync } = require('fs'); 72 | const { join } = require('path'); 73 | const filePath = join(process.cwd(), 'data', 'settings.json'); 74 | 75 | if (existsSync(filePath)) { 76 | const content = readFileSync(filePath).toString(); 77 | try { 78 | token = JSON.parse(decrypt(content)).token; 79 | } catch (err) { 80 | console.error('There was issue parsing settings.json! ', err.stack || err); 81 | } 82 | } else { 83 | console.error('Could not find the settings.json file'); 84 | } 85 | 86 | if (!token) { 87 | console.error("Token must be supplied in 'settings.json' in the data folder, double check your bot settings!"); 88 | } 89 | 90 | // Create your ShardingManger instance 91 | const manager = new ShardingManager(startup, { 92 | // for ShardingManager options see: 93 | // https://discord.js.org/#/docs/main/stable/class/ShardingManager 94 | totalShards, 95 | token, 96 | }); 97 | 98 | manager.on('shardCreate', (shard) => console.log(`Shard ${shard.id} launched`)); 99 | 100 | manager.spawn(); 101 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2021 DBM Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------