├── config.json ├── package.json ├── readme.md ├── commands └── setchannel.js └── index.js /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix": "w!", 3 | "token": "set_token_here" 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "welcomebot", 3 | "version": "1.0.0", 4 | "description": "A Welcome bot", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Exploit#1337", 10 | "license": "ISC", 11 | "dependencies": { 12 | "discord.js": "^11.3.2", 13 | "fs": "0.0.1-security", 14 | "jimp": "^0.6.0", 15 | "ms": "^2.1.1", 16 | "quick.db": "^7.0.0-b22" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Welcome Bot # 2 | In config.json set your settings such as bot token/prefix 3 | 4 | This uses quick.db to set the log channels. 5 | 6 | Command to set welcome messages: 7 | ``` 8 | w!channel 9 | ``` 10 | This bot may need some adjusting on the welcome message, font is kinda big etc. This is easy to fix but I didn't since this 11 | is open source 12 | 13 | How to use Jimp (For editing this projects welcome message if needed) 14 | https://github.com/Exploit1337/jimp-discordjs 15 | 16 | Need help? 17 | Add me on discord: Exploit#1337 18 | -------------------------------------------------------------------------------- /commands/setchannel.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | var jimp = require('jimp'); 3 | const db = require("quick.db") 4 | 5 | module.exports.run = async (bot, message, args) => { 6 | 7 | let permission = message.member.hasPermission("ADMINISTRATOR"); 8 | 9 | if(!permission) return message.channel.send("You are missing the permission `ADMINISTRATOR`") 10 | 11 | let cArgs = args[0] 12 | 13 | if(isNaN(cArgs)) return message.channel.send("You must specify a valid id for the welcome channel!") 14 | 15 | try{ 16 | bot.guilds.get(message.guild.id).channels.get(cArgs).send("Welcome channel set!") 17 | 18 | db.set(`${message.guild.id}`, cArgs) 19 | 20 | message.channel.send("You have successfully set the welcome channel to <#" + cArgs + ">") 21 | return; 22 | }catch(e){ 23 | return message.channel.send("Error: missing permissions or channel doesn't exist") 24 | } 25 | 26 | 27 | } 28 | module.exports.help = { 29 | name: "channel" 30 | } 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js") 2 | const config = require("./config.json") 3 | const bot = new Discord.Client(); 4 | const fs = require("fs"); 5 | bot.commands = new Discord.Collection(); 6 | const db = require("quick.db") 7 | var jimp = require('jimp'); 8 | 9 | fs.readdir("./commands/", (err, files) => { 10 | 11 | if(err) console.log(err); 12 | 13 | let jsfile = files.filter(f => f.split(".").pop() === "js"); 14 | if(jsfile.length <= 0){ 15 | console.log("Couldn't find commands."); 16 | return; 17 | } 18 | 19 | jsfile.forEach((f, i) =>{ 20 | let props = require(`./commands/${f}`); 21 | console.log(`${f} loaded!`); 22 | bot.commands.set(props.help.name, props); 23 | }); 24 | 25 | }); 26 | 27 | 28 | bot.on("ready", () => { 29 | console.log(bot.user.username + " is online.") 30 | }); 31 | 32 | bot.on("message", async message => { 33 | //a little bit of data parsing/general checks 34 | 35 | if(message.author.bot) return; 36 | if(message.channel.type === 'dm') return; 37 | let content = message.content.split(" "); 38 | let command = content[0]; 39 | let args = content.slice(1); 40 | let prefix = config.prefix; 41 | if(!message.content.startsWith(prefix)) return; 42 | 43 | //checks if message contains a command and runs it 44 | let commandfile = bot.commands.get(command.slice(prefix.length)); 45 | if(commandfile) commandfile.run(bot,message,args); 46 | }) 47 | bot.on('guildMemberAdd', async member => { 48 | 49 | let wChan = db.fetch(`${member.guild.id}`) 50 | 51 | if(wChan == null) return; 52 | 53 | if(!wChan) return; 54 | 55 | let font = await jimp.loadFont(jimp.FONT_SANS_32_BLACK) //We declare a 32px font 56 | let font64 = await jimp.loadFont(jimp.FONT_SANS_64_WHITE) //We declare a 64px font 57 | let bfont64 = await jimp.loadFont(jimp.FONT_SANS_64_BLACK) 58 | let mask = await jimp.read('https://i.imgur.com/552kzaW.png') //We load a mask for the avatar, so we can make it a circle instead of a shape 59 | let welcome = await jimp.read('http://rovettidesign.com/wp-content/uploads/2011/07/clouds2.jpg') //We load the base image 60 | 61 | jimp.read(member.user.displayAvatarURL).then(avatar => { //We take the user's avatar 62 | avatar.resize(200, 200) //Resize it 63 | mask.resize(200, 200) //Resize the mask 64 | avatar.mask(mask) //Make the avatar circle 65 | welcome.resize(1000, 300) 66 | 67 | welcome.print(font64, 265, 55, `Welcome ${member.user.username}`) //We print the new user's name with the 64px font 68 | welcome.print(bfont64, 265, 125, `To ${member.guild.name}`) 69 | welcome.print(font64, 265, 195, `There are now ${member.guild.memberCount} users`) 70 | welcome.composite(avatar, 40, 55).write('Welcome2.png') //Put the avatar on the image and create the Welcome2.png bot 71 | try{ 72 | member.guild.channels.get(wChan).send(``, { files: ["Welcome2.png"] }) //Send the image to the channel 73 | }catch(e){ 74 | // dont do anything if error occurs 75 | // if this occurs bot probably can't send images or messages 76 | } 77 | }) 78 | 79 | 80 | 81 | }) 82 | 83 | 84 | bot.login(config.token) 85 | --------------------------------------------------------------------------------