Skip to content

Commit 730284e

Browse files
authored
init
1 parent 4cbc88b commit 730284e

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"prefix" : "$$",
3+
"token" : "MjgyNzMxNzQ3NDE2ODY2ODE2.C4qyAw.Nes5mHRLyhGt_arw_wVXkQkeOtY"
4+
}

index.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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);

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "discordbot",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC"
11+
}

0 commit comments

Comments
 (0)