This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
166 lines (162 loc) · 7.38 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
module.exports = {
Mute,
Kick,
Ban,
Unban,
Unmute
}
async function Ban(message, userIDs, reason, days, interval) {
if (!message) throw new Error("Message parameter is required.")
if (!message.member.permissions.has('BAN_MEMBERS')) throw new Error('User Missing Permissions.')
if (!message.guild.me.permissions.has('BAN_MEMBERS')) throw new Error('Client Missing Permissions.')
try {
var banned = await message.guild.fetchBans();
} catch (err) {
throw new Error(err)
}
if (banned.some((m) => m.user.id == userID)) throw new Error('User banned already.')
if (!interval) interval = 1000
if (!userIDs) throw new Error('This parameter is required.')
if (!Array.isArray(userIDs)) var userIDs = userIDs.slice().trim().split(/ +/);
for (var userID of userIDs) {
userID = userID.replace(/[^0-9]/g, '')
if (!userID) throw new Error('User ID is required parameter.')
if (isNaN(userID)) throw new Error('ID does not contains numbers only.')
if (userID.length !== 18) throw new Error("ID length should be 18.")
try {
var user = await message.client.users.fetch(`${userID}`)
} catch (err) {
throw new Error('Invalid Discord User.')
}
if (!user) throw new Error('Invalid Discord User.')
try {
var member = await message.guild.members.fetch(user.id)
} catch (err) {
var member = null
}
if (member !== null && !member.bannable) throw new Error('Cannot ban this guild member.')
setTimeout(async () => {
try {
await message.guild.members.ban(`${user.id}`, {
reason: `${reason || `Banned by ${message.member.user.tag} | ${message.member.id}`}`,
days: `${parseInt(days) || 0}`
})
} catch (err) {
throw new Error(`${err}`)
}
}, parseInt(interval))
}
}
async function Kick(message, userIDs, reason, interval) {
if (!message) throw new Error("Message parameter is required.")
if (!message.member.permissions.has('KICK_MEMBERS')) throw new Error('User Missing Permissions.')
if (!message.guild.me.permissions.has('KICK_MEMBERS')) throw new Error('Client Missing Permissions.')
if (!interval) interval = 1000
if (!userIDs) throw new Error('This parameter is required.')
if (!Array.isArray(userIDs)) var userIDs = userIDs.slice().trim().split(/ +/);
for (var userID of userIDs) {
userID = userID.replace(/[^0-9]/g, '')
if (!userID) throw new Error('User ID is required parameter.')
if (isNaN(userID)) throw new Error('ID does not contains numbers only.')
if (userID.length !== 18) throw new Error("ID length should be 18.")
try {
var member = await message.guild.members.fetch(userID)
} catch (err) {
var member = null
}
if (member == null) throw new Error('This user is not a guild member.')
if (member !== null && !member.bannable) throw new Error('Cannot ban this guild member.')
setTimeout(async () => {
try {
await member.kick(`${member.user.id}`, {
reason: `${reason || `Banned by ${message.member.user.tag} | ${message.member.id}`}`,
days: `${parseInt(days) || 0}`
})
} catch (err) {
throw new Error(`${err}`)
}
}, parseInt(interval))
}
}
async function Mute(message, userIDs, roleID, interval) {
if (!message) throw new Error("Message parameter is required.")
if (!message.guild.me.permissions.has('MANAGE_ROLES')) throw new Error('Client Missing Permissions.')
if (!interval) interval = 1000
if (!userIDs) throw new Error('This parameter is required.')
if (!Array.isArray(userIDs)) var userIDs = userIDs.slice().trim().split(/ +/);
for (var userID of userIDs) {
userID = userID.replace(/[^0-9]/g, '')
if (!userID) throw new Error('User ID is required parameter.')
if (isNaN(userID)) throw new Error('ID does not contains numbers only.')
if (userID.length !== 18) throw new Error("ID length should be 18.")
try {
var member = await message.guild.members.fetch(userID)
} catch (err) {
throw new Error('User not in guild.')
}
if (!message.guild.roles.cache.has(roleID)) throw new Error('No Mute role found.')
if (member.roles.cache.has(roleID)) throw new Error('User Already muted.')
setTimeout(async () => {
try {
await member.roles.add(roleID)
} catch (err) {
throw new Error(err)
}
}, parseInt(interval))
}
}
async function Unban(message, userIDs, interval) {
if (!message) throw new Error("Message parameter is required.")
if (!message.member.permissions.has('BAN_MEMBERS')) throw new Error('User Missing Permissions.')
if (!message.guild.me.permissions.has('BAN_MEMBERS')) throw new Error('Client Missing Permissions.')
if (!interval) interval = 1000
if (!userIDs) throw new Error('This parameter is required.')
if (!Array.isArray(userIDs)) var userIDs = userIDs.slice().trim().split(/ +/);
try {
var banned = await message.guild.fetchBans();
} catch (err) {
throw new Error(err)
}
for (var userID of userIDs) {
userID = userID.replace(/[^0-9]/g, '')
if (!userID) throw new Error('User ID is required parameter.')
if (isNaN(userID)) throw new Error('ID does not contains numbers only.')
if (userID.length !== 18) throw new Error("ID length should be 18.")
if (!banned.some((m) => m.user.id == userID)) throw new Error('User not banned.')
console.log('k')
setTimeout(async () => {
try {
message.guild.members.unban(userID)
} catch (err) {
throw new Error(err)
}
}, parseInt(interval))
}
}
async function Unmute(message, userIDs, roleID, interval) {
if (!message) throw new Error("Message parameter is required.")
if (!message.guild.me.permissions.has('MANAGE_ROLES')) throw new Error('Client Missing Permissions.')
if (!interval) interval = 1000
if (!userIDs) throw new Error('This parameter is required.')
if (!Array.isArray(userIDs)) var userIDs = userIDs.slice().trim().split(/ +/);
for (var userID of userIDs) {
userID = userID.replace(/[^0-9]/g, '')
if (!userID) throw new Error('User ID is required parameter.')
if (isNaN(userID)) throw new Error('ID does not contains numbers only.')
if (userID.length !== 18) throw new Error("ID length should be 18.")
try {
var member = await message.guild.members.fetch(userID)
} catch (err) {
throw new Error('User not in guild.')
}
if (!message.guild.roles.cache.has(roleID)) throw new Error('No Mute role found.')
if (member.roles.cache.has(roleID)) throw new Error('User Already muted.')
setTimeout(async () => {
try {
await member.roles.remove(roleID)
} catch (err) {
throw new Error(err)
}
}, parseInt(interval))
}
}