|
| 1 | +require('dotenv').config() |
| 2 | +const axios = require('axios'); |
| 3 | + |
| 4 | +const Discord = require('discord.js') |
| 5 | +const bot = new Discord.Client() |
| 6 | +const token = process.env.TOKEN_OSDC |
| 7 | + |
| 8 | +bot.on('ready', () => { |
| 9 | + console.log('The bot is online!!!!') |
| 10 | +}) |
| 11 | + |
| 12 | + |
| 13 | +//Greeting message for a New user!!! |
| 14 | + |
| 15 | +bot.on('guildMemberAdd',member => { |
| 16 | + const channel = member.guild.channels.cache.find(ch => ch.name === 'member-log'); |
| 17 | + if(!channel) return ; |
| 18 | + message.channel.send(`Hello ${message.author} Welcome to OSDC Discord Server..Please introduce yourself!!`) |
| 19 | +}) |
| 20 | + |
| 21 | +//help command |
| 22 | + |
| 23 | +bot.on('message',message => { |
| 24 | + if(message.content === '!help') |
| 25 | + { |
| 26 | + const commandEmbedded = new Discord.MessageEmbed() |
| 27 | + .setTitle('Here are the list of commands ') |
| 28 | + .addFields( |
| 29 | + {name : '!help', value: "To view the list of commands " ,inline:false}, |
| 30 | + {name : '!website', value: "Visit our Website" ,inline:false}, |
| 31 | + {name : '!facebook', value: "Follow us on Facebook " ,inline:false}, |
| 32 | + {name : '!twitter', value: "Check us out on Twitter " ,inline:false}, |
| 33 | + {name : '!github', value: "Visit our Github Repository " ,inline:false}, |
| 34 | + {name : '!telegram', value: "Join our telegram channel " ,inline:false}, |
| 35 | + {name : '!xkcd', value: "To get an xkcd comic " ,inline:false}, |
| 36 | + {name : '!irc', value: "Find us on IRC :) " ,inline:false}, |
| 37 | + {name : '!blog', value: "Get the link of OSDC blog" ,inline:false}, |
| 38 | + {name : '!instagram', value: "Follow us on instagram :) " ,inline:false}, |
| 39 | + |
| 40 | + ) |
| 41 | + message.channel.send(commandEmbedded) |
| 42 | + } |
| 43 | +}) |
| 44 | + |
| 45 | +//xkcd comic command |
| 46 | +//It first randomly generate a number between 100 to 2000 and then sends the http request with the generated number to fetch comic |
| 47 | + |
| 48 | + |
| 49 | +bot.on('message',message => { |
| 50 | +if(message.content === '!xkcd') |
| 51 | +{ |
| 52 | + let comicNo = Math.floor(Math.random() * (2000 - 100 + 1) + 100) |
| 53 | + |
| 54 | + axios.get(`http://xkcd.com/${comicNo}/info.0.json`).then(resp => { |
| 55 | + |
| 56 | + message.channel.send(resp.data.img) |
| 57 | + }); |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | +}) |
| 62 | + |
| 63 | +//Social media commands |
| 64 | + |
| 65 | +bot.on('message',message => { |
| 66 | + if(message.content === '!website') |
| 67 | + { |
| 68 | + const website = new Discord.MessageEmbed().setTitle('Visit our Website').setURL('https://osdc.netlify.app/') |
| 69 | + message.channel.send(website) |
| 70 | + } |
| 71 | + if(message.content === '!twitter') |
| 72 | + { |
| 73 | + const twitter = new Discord.MessageEmbed().setTitle('Check us out on Twitter').setURL('https://twitter.com/osdcjiit') |
| 74 | + message.channel.send(twitter) |
| 75 | + } |
| 76 | + if(message.content === '!facebook') |
| 77 | + { |
| 78 | + const facebook = new Discord.MessageEmbed().setTitle('Follow us on Facebook').setURL('https://www.facebook.com/JIIT-OSDC-169171359799320/') |
| 79 | + message.channel.send(facebook) |
| 80 | + } |
| 81 | + if(message.content === '!github') |
| 82 | + { |
| 83 | + const github = new Discord.MessageEmbed().setTitle('Take a look at our cool projects').setURL('https://github.com/osdc') |
| 84 | + message.channel.send(github) |
| 85 | + } |
| 86 | + if(message.content === '!telegram') |
| 87 | + { |
| 88 | + const telegram = new Discord.MessageEmbed().setTitle(' Join our Telegram Channel').setURL('https://t.me/jiitosdc') |
| 89 | + message.channel.send(telegram) |
| 90 | + } |
| 91 | + if(message.content === '!irc') |
| 92 | + { |
| 93 | + const irc = new Discord.MessageEmbed().setTitle(' Join us on IRC server of Freenode at #jiit-lug').setURL('https://github.com/osdc/community-committee/wiki/IRC') |
| 94 | + message.channel.send(irc) |
| 95 | + } |
| 96 | + if(message.content === '!blog') |
| 97 | + { |
| 98 | + const blog = new Discord.MessageEmbed().setTitle('Blogs written by the folks at the Open Source Developers Community').setURL('https://osdcblog.netlify.com/') |
| 99 | + message.channel.send(blog) |
| 100 | + } |
| 101 | + |
| 102 | + if(message.content === '!instagram') |
| 103 | + { |
| 104 | + message.channel.send('https://tenor.com/view/dont-do-that-avengers-black-panther-we-dont-do-that-here-gif-12042935') |
| 105 | + } |
| 106 | + |
| 107 | +}) |
| 108 | + |
| 109 | + |
| 110 | + bot.login(token) |
0 commit comments