├── LICENSE ├── README.md ├── app.js └── storages ├── config.json └── guildConf.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 NeilTheCoder 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Custom Prefix 2 | - **Take Note: This is not Recomended for bots in Huge Servers, JSON Files can get Corrupt.** 3 | 4 | ### Installing 5 | - **On your Terminal, do `npm i --save discord.js fs` ( That will install Discord.js and fs )** 6 | 7 | ### What to Do 8 | - **Add your Bot Token on the config.json File and you can set your own Prefix there** 9 | - **[ Optional But if your Bot is in Guilds, do this > ] If your bot is in Guilds, please add the Guild id there and a prefix** 10 | 11 | ### Credits 12 | **Tbh, none helped me except me.** 13 | My Username: **Boujee#9310** 14 | My Server: **https://discord.gg/xTwAJNu** 15 | 16 | ### Questions 17 | **Q**: Ain't fs an API of Node? 18 | **A**: It is, and you don't need to Install, but it will give you the Experimental one, so i suggest, install it. 19 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js'); // Gets The Discord.js Package 2 | const fs = require("fs"); // Gets the fs Package 3 | const bot = new Discord.Client(); // Our Discord Client defined as bot 4 | 5 | var config = require('./storages/config.json'); // Config File 6 | var guildConf = require('./storages/guildConf.json'); 7 | 8 | bot.on('ready', () => { // If the Bot went on, proceed 9 | console.log('I\'m Online!'); 10 | }); 11 | 12 | bot.on('guildCreate', (guild) => { // If the Bot was added on a server, proceed 13 | if (!guildConf[guild.id]) { // If the guild's id is not on the GUILDCONF File, proceed 14 | guildConf[guild.id] = { 15 | prefix: config.prefix 16 | } 17 | } 18 | fs.writeFile('./storages/guildConf.json', JSON.stringify(guildConf, null, 2), (err) => { 19 | if (err) console.log(err) 20 | }) 21 | }); 22 | 23 | 24 | bot.on('guildDelete', (guild) => { // If the Bot was removed on a server, proceed 25 | delete guildConf[guild.id]; // Deletes the Guild ID and Prefix 26 | fs.writeFile('./storages/guildConf.json', JSON.stringify(guildConf, null, 2), (err) => { 27 | if (err) console.log(err) 28 | }) 29 | }); 30 | 31 | 32 | bot.on('message', (message) => { 33 | if (message.channel.type === "dm" || message.author.bot || message.author === bot.user) return; // Checks if we're on DMs, or the Author is a Bot, or the Author is our Bot, stop. 34 | var args = message.content.split(' ').slice(1); // We need this later 35 | var command = message.content.split(' ')[0].replace(guildConf[message.guild.id].prefix, ''); // Replaces the Current Prefix with this 36 | 37 | if (command === "ping") { // If your command is ping, proceed 38 | message.channel.send('pong!') // Reply pong! 39 | } else 40 | if (command === "prefix") { 41 | guildConf[message.guild.id].prefix = args[0]; 42 | if (!guildConf[message.guild.id].prefix) { 43 | guildConf[message.guild.id].prefix = config.prefix; // If you didn't specify a Prefix, set the Prefix to the Default Prefix 44 | } 45 | fs.writeFile('./storages/guildConf.json', JSON.stringify(guildConf, null, 2), (err) => { 46 | if (err) console.log(err) 47 | }) 48 | } 49 | }); 50 | 51 | bot.login(config.token); 52 | -------------------------------------------------------------------------------- /storages/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix": "!", 3 | "token": "Bot Token" 4 | } 5 | -------------------------------------------------------------------------------- /storages/guildConf.json: -------------------------------------------------------------------------------- 1 | { 2 | "Your Guild ID": { 3 | "prefix": "!" 4 | } 5 | } 6 | --------------------------------------------------------------------------------