|
| 1 | +const Discord = require('discord.js'); |
| 2 | +const client = new Discord.Client(); |
| 3 | + |
| 4 | +const config = require("./config.json") |
| 5 | + |
| 6 | +client.on('ready', () => { |
| 7 | + console.log('I am ready!'); |
| 8 | +}); |
| 9 | + |
| 10 | +client.on("guildMemberAdd", member => { |
| 11 | + let guild = member.guild; |
| 12 | + guild.defaultChannel.sendMessage(`Welcome ${member.user} to this server.`); |
| 13 | +}); |
| 14 | + |
| 15 | +client.on("guildCreate", guild => { |
| 16 | + console.log(`New guild added : ${guild.name}, owned by ${guild.owner.user.username}`) |
| 17 | +}); |
| 18 | + |
| 19 | +client.on("presenceUpdate", (oldMember, newMember) => { |
| 20 | + let guild = newMember.guild; |
| 21 | + let playRole = guild.roles.find("name", "Playing Minecraft"); |
| 22 | + if(!playRole) return; |
| 23 | + |
| 24 | + if(newMember.user.presence.game && newMember.user.presence.game.name.startsWith("Minecraft")) { |
| 25 | + newMember.addRole(playRole); |
| 26 | + }else if(!newMember.user.presence.game && newMember.roles.has(playRole.id)) { |
| 27 | + |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +client.on('message', message => { |
| 32 | + if(message.author.bot) return; |
| 33 | + if(!message.content.startsWith(config.prefix)) return; |
| 34 | + |
| 35 | + let command = message.content.split(" ")[0]; |
| 36 | + |
| 37 | + command = command.slice(config.prefix.length); |
| 38 | + |
| 39 | +let args = message.content.split(" ").slice(1); |
| 40 | + |
| 41 | +if (command === "math") { |
| 42 | + let numArray = args.map(n=> parseInt(n)); |
| 43 | + let math = args[1]; |
| 44 | + if (math === "+") { |
| 45 | + message.channel.sendMessage(numArray[0] + numArray[2]); |
| 46 | + } |
| 47 | + if (math === "-") { |
| 48 | + message.channel.sendMessage(numArray[0] - numArray[2]); |
| 49 | + } |
| 50 | + if (math === "/") { |
| 51 | + message.channel.sendMessage(numArray[0] / numArray[2]); |
| 52 | + } |
| 53 | + if (math === "*") { |
| 54 | + message.channel.sendMessage(numArray[0] * numArray[2]); |
| 55 | + } |
| 56 | + |
| 57 | +} |
| 58 | + |
| 59 | +if (command === "say") { |
| 60 | + message.channel.sendMessage(args.join(" ")); |
| 61 | +} |
| 62 | + |
| 63 | + if (command === "ping") { |
| 64 | + message.channel.sendMessage("pong"); |
| 65 | + } else |
| 66 | + if (command === "foo") { |
| 67 | + message.channel.sendMessage("bar!"); |
| 68 | + } |
| 69 | +}); |
| 70 | + |
| 71 | +client.login(config.token); |
0 commit comments