-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
240 lines (205 loc) · 7.63 KB
/
bot.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
229
230
231
232
233
234
235
236
237
238
239
240
const botSettings = require("./botSettings.json");
const discord = require("discord.js");
const fs = require("fs");
const ServerData = require("./ServerData.json");
const bot = new discord.Client({disableEveryone: true});
const prefix = botSettings.prefix
const Permissions = botSettings.Permissions
var JoinRole = null
var BotRole = null
var WelcomechannelId = null
var BotRole = null
// sends a mesg to the console if the bot is ready
bot.on("ready", async () => {
console.log(`Bot is ready! ${bot.user.username}`);
try {
let link = await bot.generateInvite(Permissions);
console.log(link);
} catch (e) {
console.log(e.stack);
}
});
// instialize Server Data when the bot joins
bot.on("guildCreate", (guild) => {
let channel = bot.channels.get(guild.systemChannelID || WelcomechannelId);
//channel.send("Joined")
ServerData [guild.name] = {
WelcomechannelId: null,
JoinRole: null,
BotRole: null
}
fs.writeFile("./ServerData.json", JSON.stringify(ServerData, null, 4), err => {
if (err) throw err;
});
});
// Setting Bot role
bot.on("message", async message => {
if (message.member.hasPermission("ADMINISTRATOR")) {
let messageArray = message.content.split(" ");
let command = messageArray[0];
if (command === `${prefix}setBotRole`) {
if (message.mentions.roles.first()) {
BotRole = message.mentions.roles.first().id
ServerData[message.guild.name].BotRole = `${BotRole}`;
fs.writeFile("./ServerData.json", JSON.stringify(ServerData, null, 4), err => {
if (err) throw err;
});
message.channel.send(`Bot role is set to <@&${BotRole}>`);
}
else {
message.channel.send(`Role not found`);
}
}
}
else {
message.channel.send(`You do not have permission to set Join Role ${message.author}`);
}
});
// Setting join role
bot.on("message", async message => {
let member = message.mentions.members.first() || message.member
if (message.member.hasPermission("ADMINISTRATOR")) {
let messageArray = message.content.split(" ");
let command = messageArray[0];
if (command === `${prefix}setJoinRole`) {
if (message.mentions.roles.first()) {
JoinRole = message.mentions.roles.first().id
ServerData[message.guild.name].JoinRole = `${JoinRole}`;
fs.writeFile("./ServerData.json", JSON.stringify(ServerData, null, 4), err => {
if (err) throw err;
});
message.channel.send(`Join role is set to <@&${JoinRole}>`);
}
else {
message.channel.send(`Role not found`);
}
}
}
else {
message.channel.send(`You do not have permission to set Join Role ${message.author}`);
}
});
// Setting Welcome Channel Id
bot.on("message", async message => {
let member = message.mentions.members.first() || message.member
if (message.member.hasPermission("ADMINISTRATOR")) {
let messageArray = message.content.split(" ");
let command = messageArray[0];
let channel = bot.channels.get(message.guild.systemChannelID || WelcomechannelId);
if (command === `${prefix}setWelcomeChannelid`) {
WelcomechannelId = messageArray[1]
message.channel.send(`Your welcome channel is set to ${"`"+message.guild.channels.get(WelcomechannelId).name+"`"}`);
ServerData[message.guild.name].WelcomechannelId = WelcomechannelId
fs.writeFile("./ServerData.json", JSON.stringify(ServerData, null, 4), err => {
if (err) throw err;
});
}
}
else {
message.channel.send(`You do not have permission to set Join Role ${message.author}`);
}
});
// Welcome msg
bot.on("guildMemberAdd", member => {
WelcomechannelId = ServerData[member.guild.name].WelcomechannelId
let channel = bot.channels.get(member.guild.systemChannelID || WelcomechannelId);
JoinRole = ServerData[member.guild.name].JoinRole
BotRole = ServerData[member.guild.name].BotRole
var joinRole = member.guild.roles.find("id",JoinRole)
var botRole = member.guild.roles.find("id",BotRole)
if (WelcomechannelId === null) {
channel.send(`👋Welcome ${member}👋, hope you have great time in 🎉${member.guild.name}🎉`);
member.addRole(joinRole);
}
else {
member.guild.channels.get(WelcomechannelId).send(`👋Welcome ${member}, hope you have great time in 🎉${member.guild.name}🎉`);
if (member.user.bot) {
member.addRole(joinRole);
member.addRole(botRole);
}
else {
member.addRole(joinRole);
}
}
})
//Userinfo cmd, Kick Cmd
bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let command = messageArray[0];
let args = messageArray.slice(1);
if(!command.startsWith(prefix)) return;
if(command === `${prefix}info`) {
if (message.mentions.members.first()){
let member = message.mentions.members.first() || message.member
let embed = new discord.RichEmbed()
.setAuthor(message.mentions.users.first().username, message.mentions.users.first().avatarURL)
.setTitle("Info")
.addField('Highest Role', member.highestRole.name)
.addField('Current Nickname',member.nickname)
.addField('User Tag', message.mentions.users.first().tag)
.setColor("#EDF4B6")
.setThumbnail(message.mentions.users.first().avatarURL);
message.channel.sendEmbed(embed)
return;
}
else if (message.content === `${prefix}info`) {
let embed = new discord.RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle("Info")
.addField('Highest Role', message.member.highestRole.name)
.addField('Current Nickname', message.member.nickname)
.addField('User Tag', message.author.tag)
.setColor("#EDF4B6")
.setThumbnail(message.author.avatarURL);
message.channel.sendEmbed(embed)
return;
}
else {
message.channel.send(`Error, try mentioning a member. ${message.author}`);
}
}
//kick command
if(command === `${prefix}kick`) {
let member = message.mentions.members.first() || message.member
if (message.member.hasPermission("KICK_MEMBERS")) {
if (message.mentions.members.first()){
if (member.displayName === bot.user.username) {
message.channel.send(`You cant Kick me BOI!!!`);
}
else {
member.kick();
message.channel.send(`${member.displayName} is kicked`);
}
}
else {
message.channel.send(`Error, try mentioning a member. ${message.author}`);
}
}
else {
message.channel.send(`you dont hav perm ${message.author}`);
}
}
if(command === `${prefix}ban`) {
let member = message.mentions.members.first() || message.member
if (message.member.hasPermission("BAN_MEMBERS")) {
if (message.mentions.members.first()){
if (member.displayName === bot.user.username) {
message.channel.send(`You cant Ban me BOI!!!`);
}
else {
member.ban(7);
message.channel.send(`${member.displayName} is Banned`);
}
}
else {
message.channel.send(`Error, try mentioning a member. ${message.author}`);
}
}
else {
message.channel.send(`you dont hav perm ${message.author}`);
}
}
});
bot.login(process.env.botSettings.token);