├── .env ├── LICENSE ├── README.md ├── commands ├── chat.js └── setchat.js ├── events └── chatEvent.js ├── index.js ├── package.json └── util ├── chatSend.js ├── embed.js └── inline.js /.env: -------------------------------------------------------------------------------- 1 | bid = "put brainshop bid here" 2 | key = "put brainshop key here" 3 | token = "put discord bot token here" 4 | mongoUrl= "paste your mongo url here" 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Gogeta 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 | # Discord-Chatbot 2 | An Open Source Chatbot for Discord | Discord.js | Made By Acê#1234 3 | > Powered By Brainshop 4 | 5 | ## Brainshop 6 | to get brainshop key, follow the steps below 7 | * Create an account on [brainshop.ai](https://brainshop.ai/) 8 | * Once you logged in, Click on Create Brain/ Add Brain 9 | * Click on "Create a Root Brain", Enter any Name 10 | 11 | #### do the same settings as shown below: 12 | ![settings](https://cdn.discordapp.com/attachments/837202281618866207/837202384563994684/unknown.png) 13 | 14 | * Save the api details 15 | * Fill them in .env (this will keep your details private) 16 | 17 | ## MongoDb 18 | to get mongoUrl, follow the steps below 19 | * Create an account/Sign Up with Google on [MongoDb](https://www.mongodb.com/) 20 | * Create Free Cluster, name it anything 21 | * Copy the mongourl, put your password in it 22 | * go to network access and whitelist 0.0.0.0/0 ip to access it from anywhere 23 | * paste the url in .env 24 | 25 | ### Bot Installation | Self Host 26 | * Extract `.zip` in a folder 27 | * Run `npm install` 28 | * Fill details (Bid, Key, Token) 29 | * Run `node index.js` in console 30 | 31 | ### Bot Installition | Glitch/ Repl 32 | * Copy url of the repository 33 | * Go to [Glitch](https://glitch.com/)/ [Repl](https://replit.com/) 34 | * Click on `Import From Github` 35 | * Paste this url there 36 | * Wait till it imports 37 | * Fill the details in .env (Bid, Key, Token) 38 | * Start it 39 | 40 | ### Detailed Installation 41 | [Youtube](https://www.youtube.com/channel/UCkpN5Xw5EMqoPsfQWKpYYwA) 42 | 43 | ### [Support Server](https://discord.gg/ddEmXUPCE4) 44 | any error or problem while running the code? join the server for support 45 | 46 | ### Screenshot 47 | ![Chatbot](https://cdn.discordapp.com/attachments/837202281618866207/837217805640138762/Capture.PNG) 48 | 49 | ### Credits 50 | [Brainshop.ai](https://brainshop.ai/) 51 | 52 | -------------------------------------------------------------------------------- /commands/chat.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports.run = async(client, message, args) => { 3 | client.brain.chatSend(message) 4 | } 5 | module.exports.config = { 6 | name: 'chat' 7 | } -------------------------------------------------------------------------------- /commands/setchat.js: -------------------------------------------------------------------------------- 1 | module.exports.run = async(client, message, args) => { 2 | let db = client.db 3 | if (!message.member.hasPermission("ADMINSTRATOR")) return message.channel.send(client.em("", "You don't have permissions to do this. D:")) 4 | if(!args[0]) return message.channel.send(client.em("", "how about you mention a channel or give a channel id. :/")) 5 | let channel = message.mentions.channels.first() || message.guild.channels.cache.get(args[0]) 6 | if (!channel) return message.channel.send(client.em('', 'This is not a channel')) 7 | 8 | db.set(`${message.guild.id}_chatchannel`, `${channel.id}`) 9 | message.channel.send(client.em('Chat Channel', `Chat Channel of this server is set to ${channel}`)) 10 | } 11 | module.exports.config = { 12 | name: 'setchat', 13 | aliases: ['sc'] 14 | } -------------------------------------------------------------------------------- /events/chatEvent.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | event: "message", // Event 4 | once: false, 5 | async run (message, client) { 6 | if(message.author.bot) return 7 | let db = client.db 8 | if(await db.has(`${message.guild.id}_chatchannel`)) { 9 | let channelid = await db.get(`${message.guild.id}_chatchannel`) 10 | if (!channelid) return 11 | if(channelid != message.channel.id) return 12 | client.brain.chatSend(message) 13 | } 14 | } 15 | }; -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // .ENV 2 | require("dotenv").config(); 3 | // Express | Ignore this if you're gonna self host 4 | const chalk = require('chalk'); 5 | const express = require('express') 6 | const app = express() 7 | const port = 8080 8 | 9 | app.get('/', (req, res) => { 10 | res.send('Server Online!') // Tell in comments 11 | }) 12 | 13 | app.listen(port, () => { 14 | console.log(`${chalk.green(`Server online!`)}`) 15 | }) 16 | 17 | // Code 18 | const fs = require('fs'); 19 | const Discord = require('discord.js'); 20 | const client = new Discord.Client({disableEveryone: true}); 21 | client.brain = require('./util/chatSend'); 22 | client.em = require("./util/embed") 23 | client.commands = new Discord.Collection(); 24 | client.aliases = new Discord.Collection(); 25 | 26 | // Database Mongo 27 | /* 28 | const { Database } = require("quickmongo"); 29 | client.db = new Database(process.env.mongoUrl); 30 | 31 | client.db.on("ready", () => { 32 | console.log(" ==========================\n Mongo Database connected!\n =========================="); 33 | }) 34 | */ 35 | // Database Quick.db 36 | client.db = require('quick.db'); 37 | 38 | // Don't use both at same time or code will stop working 39 | 40 | // Ready 41 | client.on('ready', () => { 42 | console.log(`${client.user.username} is Online`) 43 | setInterval(async () => { 44 | const statuses = [`.help`, `Discord-Chatbot`] 45 | client.user.setActivity(statuses[Math.floor(Math.random() * statuses.length)], { type: "STREAMING", url: "https://www.twitch.tv/discord"}) 46 | }, 10000) 47 | }); 48 | 49 | // Event Handler 50 | fs.readdir('./events/', (err, files) => { 51 | if (err) return console.error(err); 52 | files.forEach(file => { 53 | const eventFunction = require(`./events/${file}`); 54 | if (eventFunction.disabled) return; 55 | 56 | const event = eventFunction.event || file.split('.')[0]; 57 | const emitter = (typeof eventFunction.emitter === 'string' ? client[eventFunction.emitter] : eventFunction.emitter) || client; 58 | const once = eventFunction.once; 59 | 60 | try { 61 | emitter[once ? 'once' : 'on'](event, (...args) => eventFunction.run(...args, client)); 62 | } catch (error) { 63 | console.error(error.stack); 64 | } 65 | }); 66 | }); 67 | 68 | // Command Handler 69 | client.on("message", async message => { 70 | if (message.author.bot || message.channel.type === "dm") return; 71 | // command 72 | let messageArray = message.content.split(" "), 73 | cmd = messageArray[0].toLowerCase(), 74 | args = messageArray.slice(1), 75 | prefix = "."; // Add Prefix 76 | 77 | if (!message.content.startsWith(prefix)) return; 78 | let commandfile = client.commands.get(cmd.slice(prefix.length)) || client.commands.get(client.aliases.get(cmd.slice(prefix.length))); 79 | if (commandfile) commandfile.run(client, message, args); 80 | 81 | }); 82 | 83 | 84 | fs.readdir("./commands/", (err, files) => { 85 | if (err) console.log(err); 86 | let jsfile = files.filter(R => R.endsWith('.js')); 87 | if (jsfile.length <= 0) { 88 | return console.log(chalk.red("There are no commands")); 89 | } 90 | jsfile.forEach((f, i) => { 91 | let pull = require(`./commands/${f}`); 92 | console.log(`Loaded - ${f} | ${pull.config.aliases}`) 93 | 94 | client.commands.set(pull.config.name, pull); 95 | if (pull.config.aliases) pull.config.aliases.forEach(alias => client.aliases.set(alias, pull.config.name)) 96 | }); 97 | }); 98 | // Login 99 | client.login(process.env.token); // Your Discord Bot Token 100 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "brain-chatbot", 3 | "version": "1.0.0", 4 | "description": "Discord.js Chatbot using Brainshop.ai | Rup#2626", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "author": "Rup-1234", 10 | "license": "MIT", 11 | "engines": { 12 | "node": "12.x" 13 | }, 14 | "dependencies": { 15 | "axios": "^0.21.1", 16 | "chalk": "^4.1.1", 17 | "discord.js": "^12.5.3", 18 | "express": "^4.17.1", 19 | "quick.db": "^7.1.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /util/chatSend.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | 3 | require("./inline.js"); 4 | 5 | const chatSend = async (message) => { 6 | try { 7 | let bid = process.env.bid // Your Bid From Brainshop.ai 8 | let key = process.env.key // Your Key From Brainshop.ai 9 | let uid = "1" 10 | let msg = message.content 11 | message.channel.startTyping() 12 | await axios.get(`http://api.brainshop.ai/get?bid=${bid}&key=${key}&uid=${uid}&msg=${msg}`) 13 | .then(res => { 14 | let data = res.data; 15 | let reply = data.cnt 16 | console.log(reply) 17 | if (reply) { 18 | message.channel.stopTyping(); 19 | message.sendInline(reply, { allowedMentions: { repliedUser: false } }); 20 | } else if(!reply) { 21 | message.channel.stopTyping(); 22 | message.sendInline("api did not respond at time [TIME OUT]", { allowedMentions: { repliedUser: false } }); 23 | } 24 | }) 25 | } catch (e) { 26 | message.channel.stopTyping(); 27 | console.log(e); 28 | } 29 | }; 30 | 31 | module.exports = { 32 | chatSend 33 | }; 34 | -------------------------------------------------------------------------------- /util/embed.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js'); 2 | const client = new Discord.Client(); 3 | 4 | function embed (title, des, foot, thum){ 5 | if(!des) des = "" 6 | if(!foot) foot = "" 7 | const em = new Discord.MessageEmbed() 8 | .setTitle(title) 9 | .setColor('#1BB1B0') 10 | .setThumbnail(thum) 11 | .setDescription(des) 12 | .setFooter(foot) 13 | return em 14 | } 15 | 16 | module.exports = embed 17 | -------------------------------------------------------------------------------- /util/inline.js: -------------------------------------------------------------------------------- 1 | const { APIMessage, Structures } = require("discord.js"); 2 | 3 | class ExtAPIMessage extends APIMessage { 4 | resolveData() { 5 | if (this.data) return this; 6 | super.resolveData(); 7 | if ((this.options.allowedMentions || {}).repliedUser !== undefined) { 8 | if (this.data.allowed_mentions === undefined) this.data.allowed_mentions = {}; 9 | Object.assign(this.data.allowed_mentions, { replied_user: this.options.allowedMentions.repliedUser }); 10 | delete this.options.allowedMentions.repliedUser; 11 | } 12 | if (this.options.replyTo !== undefined) { 13 | Object.assign(this.data, { message_reference: { message_id: this.options.replyTo.id } }); 14 | } 15 | return this; 16 | } 17 | } 18 | 19 | class Message extends Structures.get("Message") { 20 | sendInline(content, options) { 21 | return this.channel.send(ExtAPIMessage.create(this, content, options, { replyTo: this }).resolveData()); 22 | } 23 | 24 | edit(content, options) { 25 | return super.edit(ExtAPIMessage.create(this, content, options).resolveData()); 26 | } 27 | } 28 | 29 | Structures.extend("Message", () => Message); 30 | --------------------------------------------------------------------------------