-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
164 lines (147 loc) · 7 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
const { Client, GatewayIntentBits, PermissionsBitField } = require('discord.js')
require('dotenv/config')
// these should be in a separate config file
var prefix = '!';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
})
client.on('ready', ()=>{
console.log('Bot is Online!')
})
client.on('messageCreate', async message => {
if (message.content.substring(0, (prefix.length)) == prefix) {
var msgArgs = message.content.split(' ');
switch (msgArgs[0].substring(prefix.length)) {
case 'clear':
try {
const fetched = await message.channel.messages.fetch({ limit: 100 });//bot clear
message.channel.bulkDelete(fetched);
} catch (error) {
console.log(`Error while clearing messages: ${error}`);//catch error
message.channel.reply('Error while clearing messages!');
}
break;
case 'kick':
try {
if (!message.member.permissions.has(PermissionsBitField.Flags.KickMembers)) {
message.reply('Insufficient Permissions.');
} else {
if (!msgArgs[1]) {
message.reply('Please specify a user to kick.');
} else {
const target = message.mentions.members.first();
if (target.id === message.member.id) {
message.reply('Cannot kick self.');
} else if (target.roles.highest.position >= message.member.roles.highest.position) {
message.reply('Cannot kick users with a higher rank.');
} else {
if (!target.kickable) {
message.reply('Cannot kick that user.');
} else {
(await target.kick()) + message.reply('User successfully kicked.');
}
}
}
}
} catch (error) {
console.log(error);
message.reply('Error.');
}
break;
case 'ban':
try {
if (!message.member.permissions.has(PermissionsBitField.Flags.BanMembers)) {
message.reply('Insufficient Permissions.');
} else {
if (!msgArgs[1]) {
message.reply('Please specify a user to ban.');
} else {
const target = message.mentions.members.first();
if (target.id === message.member.id) {
message.reply('Cannot ban self.');
} else if (target.roles.highest.position >= message.member.roles.highest.position) {
message.reply('Cannot ban users with a higher rank.');
} else {
if (!target.bannable) {
message.reply('Cannot ban that user.');
} else {
(await target.ban()) + message.reply('User successfully banned.');
}
}
}
}
} catch (error) {
console.log(error);
message.reply('Error.');
}
break;
case 'mute':
try {
const mutedRole = message.guild.roles.cache.find((role) => role.name === 'Muted');
if (!mutedRole) {
message.reply('No Muted Role. Please contact an administrator.');
}
else if (!message.member.permissions.has(PermissionsBitField.Flags.MuteMembers)) {
message.reply('Insufficient Permissions.');
} else {
if (!msgArgs[1]) {
message.reply('Please specify a user to mute.');
} else {
const target = message.mentions.members.first();
if (target.roles.highest.position >= message.member.roles.highest.position) {
message.reply('Cannot mute users with a higher rank.');
} else {
target.roles.add(mutedRole);
message.reply('User successfully muted.');
}
}
}
} catch (error) {
console.log(error);
message.reply('Error.');
}
break;
case 'unmute':
try {
const mutedRole = message.guild.roles.cache.find((role) => role.name === 'Muted');
if (!mutedRole) {
message.reply('No Muted Role. Please contact an administrator.');
}
else if (!message.member.permissions.has(PermissionsBitField.Flags.MuteMembers)) {
message.reply('Insufficient Permissions.');
} else {
if (!msgArgs[1]) {
message.reply('Please specify a user to unmute.');
} else {
const target = message.mentions.members.first();
if (target.roles.highest.position >= message.member.roles.highest.position) {
message.reply('Cannot unmute users with a higher rank.');
} else {
target.roles.remove(mutedRole);
message.reply('User successfully unmuted.');
}
}
}
} catch (error) {
console.log(error);
message.reply('Error.');
}
break;
default:
message.reply('Unrecognized command.');
}
}
else {
if (message.content.toLowerCase().includes('stupid')) { //bad word
message.reply('Please refrain from using inappropriate language!'); //bots warning
}
if (message.content.toLowerCase().includes('hello')) {//Greeting
message.reply('Hi there!');//bot response
}
}
});
client.login(process.env.TOKEN)