-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
228 lines (192 loc) · 7.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
const botconfig = require("./botconfig.json");
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client();
const moment = require('moment');
require("moment-duration-format");
const ms = require("ms");
bot.commands = new Discord.Collection();
let xp = require("./xp.json");
let orange = botconfig.orange;
let prefix = botconfig.prefix;
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0){
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} is succesfully loaded.`);
bot.commands.set(props.help.name, props);
});
})
//bot playing with wolves
bot.on("ready", async () => {
console.log(`${bot.user.username} is running and connected to Discord! ${bot.user.username} should run without any errors.`);
bot.user.setActivity("Prefix: >", {type: "PLAYING"});
bot.user.setStatus("Online");
var files = ['index.js'];
for (var index in files) {
(function (filename) {
fs.readFile("./index.js", "utf8", function(err, data) {
// You can use 'filename' here as well.
console.log(`Reading ${filename}`);
});
}(files[index]));
}
});
//guildCreate
bot.on("guildCreate", guild =>{
bot.guilds.map(g => g.owner.username + guild.name);
let owner = guild.owner;
owner.send("Thanks for using my bot. This bot has to have administrator permission and some channels called logs, incidents, ideas, reports and announcements. If you have any questions you can contact me using discord: Cassieboy2001#8330");
console.log(`New guild added : ${guild.name}, owned by ${guild.owner.user.username}`);
});
bot.on("guildDelete", guild => {
// this event triggers when the bot is removed from a guild.
console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
});
//guildMemberAdd
bot.on("guildMemberAdd", async member => {
let bots = member.guild.members.filter(m => m.user.bot).size;
let humans = member.guild.members.filter(m => !m.user.bot).size;
console.log(`${member.user} joined the squad.`);
let aicon = member.guild.iconURL;
let role = member.guild.roles.find("name", "member");
let welcomechannel = member.guild.channels.find(`name`, "welcome");
let welcomeembed = new Discord.RichEmbed()
.setTitle("Welcome!")
.setColor("#00ff26")
.setDescription(`${member.user} Welcome to the pack! We now have ${member.guild.memberCount} members.`);
welcomechannel.send(welcomeembed)
function getUpdates(i) {
const mcChannel = i.guild.channels.find(`id`, "460829572875681812");
const hchannel = i.guild.channels.find(`id`, "460829762600828938");
const bchannel = i.guild.channels.find(`id`, "460829821518217216");
mcChannel.setName(`Member Count: ${i.guild.memberCount}`);
hchannel.setName(`Human Count: ${humans}`);
bchannel.setName(`Bot Count: ${bots}`);
}
getUpdates(member);
});
//guildMemberRemove
bot.on("guildMemberRemove", (member) => {
let bots = member.guild.members.filter(m => m.user.bot).size;
let humans = member.guild.members.filter(m => !m.user.bot).size;
console.log(`${member.user} left the squad.`);
let aicon = member.guild.iconURL;
let role = member.guild.roles.find("name", "member");
let welcomechannel = member.guild.channels.find(`name`, "welcome");
let welcomeembed = new Discord.RichEmbed()
.setTitle("Goodbye!")
.setColor("#00ff26")
.setDescription(`${member.user} is going further without a pack! We now have ${member.guild.memberCount} members.`);
welcomechannel.send(welcomeembed)
function getUpdates(i) {
const mcChannel = i.guild.channels.find(`id`, "460829572875681812");
const hchannel = i.guild.channels.find(`id`, "460829762600828938");
const bchannel = i.guild.channels.find(`id`, "460829821518217216");
mcChannel.setName(`Member Count: ${i.guild.memberCount}`);
hchannel.setName(`Human Count: ${humans}`);
bchannel.setName(`Bot Count: ${bots}`);
}
getUpdates(member);
});
//role update
bot.on("roleUpdate", async (oldRole, newRole) => {
let logchannnel = newRole.guild.channels.find(`name`, "logs");
let roleupdateembed = new Discord.RichEmbed()
.setColor("#00ff33")
.setDescription(`The role ${oldRole.name} has been changed to ${newRole.name}`);
logchannnel.send(roleupdateembed);
});
//roleCreate
bot.on("roleCreate", async role => {
let guild = role.guild;
let logchannel = role.guild.channels.find(`name`, "logs");
let roleembed = new Discord.RichEmbed()
.setColor("#00ff33")
.setDescription(`The role ${role.name} has been created!`);
logchannel.send(roleembed);
});
//roleDelete
bot.on("roleDelete", async role => {
let guild = role.guild;
let logchannel = role.guild.channels.find(`name`, "logs");
let roledelembed = new Discord.RichEmbed()
.setColor("#ff0000")
.setDescription(`The role ${role.name} has been deleted!`);
logchannel.send(roledelembed);
});
//userUpdate
bot.on("guildMemberUpdate", async (oldMember, newMember) => {
let logchannel = newMember.guild.channels.find(`name`, "logs");
let updateembed = new Discord.RichEmbed()
.setColor("#00ff33")
.setDescription(`The user ${oldMember.displayName} has been changed to ${newMember}.`);
logchannel.send(updateembed);
});
//channelCreate
bot.on("channelCreate", async channel => {
let logs = channel.guild.channels.find("name", "logs");
let channelcreateembed = new Discord.RichEmbed()
.setColor("#00ff33")
.setDescription(`There is a new channel created called: ${channel}`);
logs.send(channelcreateembed);
});
//channelDelete
bot.on("channelDelete", async channel => {
let logs = channel.guild.channels.find("name", "logs");
let channeldelembed = new Discord.RichEmbed()
.setColor("#ff0000")
.setDescription(`The channel ${channel.name} has been deleted!`);
logs.send(channeldelembed);
});
//bot message
bot.on("message", async message => {
if(!message.guild.id == "428222795164418051"){
message.kick();
}
if(message.author.bot) return;
if(message.channel.type === "dm") return;
if (message.content.indexOf(botconfig.prefix) !== 0) return;
//xp
let xpAdd = Math.floor(Math.random() * 7) + 8;
console.log(xpAdd);
if(!xp[message.author.id, message.guild.id]){
xp[message.author.id, message.guild.id] = {
xp: 0,
level: 0
};
}
let curxp = xp[message.author.id, message.guild.id].xp;
let curlvl = xp[message.author.id, message.guild.id].level
let nxtlvl = xp[message.author.id, message.guild.id].level * 100;
xp[message.author.id, message.guild.id].xp = curxp + xpAdd;
if(nxtlvl <= xp[message.author.id, message.guild.id].xp){
xp[message.author.id, message.guild.id].level = curlvl + 1;
let lvlupembed = new Discord.RichEmbed()
.setTitle("Level Up!")
.setColor(orange)
.addField("New Level", curlvl + 1);
message.channel.send(lvlupembed).then(msg => {msg.delete(5000)});
fs.writeFile("./xp.json", JSON.stringify(xp), (err) => {
if(err) console.log(err)
});
};
//let prefix = botconfig.prefix;
let messageArray = message.content.split(" ");
let cmd = messageArray[0].toLowerCase();
let args = messageArray.slice(1);
try {
let commandfile = bot.commands.get(cmd.slice(prefix.length));
if(commandfile) commandfile.run(bot, message, args);
} catch (e) {
console.log(e.message);
} finally {
console.log(`${message.author.tag} has run the command ${cmd}`);
}
});
bot.login(botconfig.token);