-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
166 lines (141 loc) · 4.82 KB
/
server.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
const botconfig = require("./botconfig.json");
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client();
const Welcome = require("discord-welcome");
bot.commands = new Discord.Collection();
let purple = botconfig.purple;
let cooldown = new Set();
let cdseconds = 0;
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} loaded!`);
bot.commands.set(props.help.name, props);
});
});
bot.on("ready", () => {
setInterval(async () => {
let textList = ["Helper Bot 2.0"];
var text = textList[Math.floor(Math.random() * textList.length)];
bot.user.setActivity(text, { type: "STREAMING" });
}, 1000); // milliseconds
});
bot.on("ready", () => {
console.log("Servers:");
bot.guilds.forEach(guild => {
console.log(" ! " + guild.name);
});
});
const invites = {};
const wait = require("util").promisify(setTimeout);
bot.on("ready", () => {
wait(1000);
// Load all invites for all guilds and save them to the cache.
bot.guilds.forEach(g => {
g.fetchInvites().then(guildInvites => {
invites[g.id] = guildInvites;
});
});
});
//------ end first part of invite module ------------ //
// welcome member message module
bot.on("guildMemberAdd", member => {
let channel = member.guild.channels.find("name", "welcome");
let memberavatar = member.user.avatarURL;
if (!channel) return;
let embed = new Discord.RichEmbed()
.setColor("RANDOM")
.setThumbnail(memberavatar)
.addField(":bust_in_silhouette: | name : ", `${member}`)
.addField(":microphone2: | Welcome!", `Welcome to the server, ${member}`)
.addField(":id: | User :", "**[" + `${member.id}` + "]**")
.addField(
":family_mwgb: | Your are the newest member",
`${member.guild.memberCount}`
)
.addField("Name", `<@` + `${member.id}` + `>`, true)
.addField("Server", `${member.guild.name}`, true)
.setFooter(`**${member.guild.name}**`)
.setTimestamp();
channel.sendEmbed(embed);
});
bot.on("guildMemberAdd", member => {
console.log(`${member}`, "has joined" + `${member.guild.name}`);
});
// leave member message module
bot.on("guildMemberRemove", member => {
let channel = member.guild.channels.find("name", "leave");
let memberavatar = member.user.avatarURL;
if (!channel) return;
let embed = new Discord.RichEmbed()
.setColor("RANDOM")
.setThumbnail(memberavatar)
.addField("Name:", `${member}`)
.addField("Has Left the Server", ";(")
.addField("Bye Bye :(", "We will all miss you!")
.addField("The server now has", `${member.guild.memberCount}` + " members")
.setFooter(`**${member.guild.name}`)
.setTimestamp();
channel.sendEmbed(embed);
});
// leave member DM message module
bot.on("guildMemberRemove", member => {
console.log(
`${member}` +
"has left " +
`${member.guild.name}` +
" Sending leave message now"
);
console.log("Leave Message Sent");
});
bot.on("message", async message => {
// bot dm module
if (message.author.bot) return;
if (message.channel.type === "dm") return;
//custom module
let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));
if (!prefixes[message.guild.id]) {
prefixes[message.guild.id] = {
prefixes: botconfig.prefix
};
}
let prefix = prefixes[message.guild.id].prefixes;
if (!message.content.startsWith(prefix)) return;
if (cooldown.has(message.author.id)) {
message.delete();
return message.reply("You have to wait 5 seconds between commands.");
}
if (!message.member.hasPermission("ADMINISTRATOR")) {
cooldown.add(message.author.id);
}
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
let commandfile = bot.commands.get(cmd.slice(prefix.length));
if (commandfile) commandfile.run(bot, message, args);
setTimeout(() => {
cooldown.delete(message.author.id);
}, cdseconds * 1000);
//channel create / delete channel module
bot.on("channelCreate", async channel => {
console.log(`${channel.name} has been created.`);
if (channel.type != "text") return;
let sChannel = channel.guild.channels.find("name", "message_log");
sChannel.send(`The channel ${channel} has been created`);
});
bot.on("channelDelete", async channel => {
console.log(`${channel.name} has been Deleted.`);
if (channel.type != "text") return;
let sChannel = channel.guild.channels.find("name", "message_log");
sChannel.send(`The channel ${channel} has been Deleted`);
});
});
bot.login(process.env.BOT_TOKEN);
//You reached then end congrats and dont judge me I need // to remember things!