-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
179 lines (160 loc) · 7.08 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
const Discord = require("discord.js")
const bot = new Discord.Client({disableMentions: 'everyone'})
const config = require("./config.json")
bot.on("ready", () => {
console.log("Loaded up!")
});
bot.on("message", message => {
if (message.author.bot) return;
if (message.content.indexOf(config.prefix) !== 0) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase()
if (command === "help") {
const helpEmbed = new Discord.MessageEmbed()
.setTitle(`${bot.user.username}'s commands`)
.setDescription(`**Prefix:** ${config.prefix}`)
.addField(`\`ping\``, `Check your bot's ping`)
.addField(`\`kick\``, `Usage: **${config.prefix}kick [@User]**\n**${config.prefix}kick [@User][Reason]**`)
.addField(`\`ban\``, `Usage: **${config.prefix}ban [@User]**\n**${config.prefix}ban [@User][Reason]**`)
.addField(`\`add\``, `Adds a role to a user \nUsage: **${config.prefix}add [@User] [Role]**`)
.addField(`\`remove\``, `Removes a role from a user \nUsage: **${config.prefix}remove [@User] [Role]**`)
.addField(`\`purge\``, `Clears a number of messages between 2 or 100 \nUsage: **${config.prefix}purge [number]**`)
.addField(`\`rps\``, `Play rock paper scissors`)
.addField(`\`say\``, `Have the bot say something`)
message.channel.send(helpEmbed)
}
if (command === "ping") {
message.channel.send(`Pong **(${Date.now() - message.createdTimestamp}ms)**`)
}
if (command === "kick") {
if (!message.member.hasPermission('KICK_MEMBERS'))
return message.channel.send("Insufficient permissions (Requires permission `Kick members`)").then(msg => {
msg.delete({ timeout: 30000 })
})
const member = message.mentions.members.first();
if (!member)
return message.channel.send("You have not mentioned a user").then(msg => {
msg.delete({ timeout: 30000 })
})
if (!member.kickable)
return message.channel.send("This user is unkickable").then(msg => {
msg.delete({ timeout: 30000 })
})
const reason = args.slice(1).join(" ")
if (member) {
if (!reason) return member.kick().then(member => {
message.channel.send(`${member.user.tag} was kicked, no reason was provided`);
})
if (reason) return member.kick().then(member => {
message.channel.send(`${member.user.tag} was kicked for ${reason}`);
})
}
}
if (command === "ban") {
if (!message.member.hasPermission('BAN_MEMBERS'))
return message.channel.send("Insufficient permissions (Requires permission `Ban members`)").then(msg => {
msg.delete({ timeout: 30000 })
})
const member = message.mentions.members.first();
if (!member)
return message.channel.send("You have not mentioned a user").then(msg => {
msg.delete({ timeout: 30000 })
})
if (!member.bannable)
return message.channel.send("This user is unbannable").then(msg => {
msg.delete({ timeout: 30000 })
})
const reason = args.slice(1).join(" ")
if (member) {
if (!reason) return member.ban().then(member => {
message.channel.send(`${member.user.tag} was banned, no reason was provided`);
})
if (reason) return member.ban(reason).then(member => {
message.channel.send(`${member.user.tag} was banned for ${reason}`);
})
}
}
if (command === "add") {
if (!message.member.hasPermission('MANAGE_ROLES'))
return message.channel.send("Insufficient permissions (Requires permission `Manage roles`)").then(msg => {
msg.delete({ timeout: 30000 })
})
const member = message.mentions.members.first()
if (!member)
return message.channel.send("You have not mentioned a user").then(msg => {
msg.delete({ timeout: 30000 })
})
const add = args.slice(1).join(" ")
if (!add)
return message.channel.send("You have not specified a role").then(msg => {
msg.delete({ timeout: 30000 })
})
const roleAdd = message.guild.roles.cache.find(role => role.name === add)
if (!roleAdd)
return message.channel.send("This role does not exist").then(msg => {
msg.delete({ timeout: 30000 })
})
if (member.roles.cache.get(roleAdd.id))
return message.channel.send(`This user already has the ${add} role`).then(msg => {
msg.delete({ timeout: 30000 })
})
member.roles.add(roleAdd.id).then((member) => {
message.channel.send(`${add} added to ${member.displayName}`)
})
}
if (command === "remove") {
if (!message.member.hasPermission('MANAGE_ROLES'))
return message.channel.send("Insufficient permissions (Requires permission `Manage roles`)").then(msg => {
msg.delete({ timeout: 30000 })
})
const member = message.mentions.members.first()
if (!member)
return message.channel.send("You have not mentioned a user").then(msg => {
msg.delete({ timeout: 30000 })
})
const remove = args.slice(1).join(" ")
if (!remove)
return message.channel.send("You have not specified a role").then(msg => {
msg.delete({ timeout: 30000 })
})
const roleRemove = message.guild.roles.cache.find(role => role.name === remove)
if (!roleRemove)
return message.channel.send("This role does not exist").then(msg => {
msg.delete({ timeout: 30000 })
})
if (!member.roles.cache.get(roleRemove.id))
return message.channel.send(`This user does not have the ${remove} role`).then(msg => {
msg.delete({ timeout: 30000 })
})
member.roles.remove(roleRemove.id).then((member) => {
message.channel.send(`${remove} removed from ${member.displayName}`)
})
}
if (command === "say") {
const text = args.join(" ")
if(!text) return message.channel.send("You have not specified something to say").then(msg => {
msg.delete({ timeout: 30000 })
})
message.channel.send(text)
}
if (command === "purge") {
if(!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send("Insufficient permissions (requires permission `Manage messages`)").then(msg => {
msg.delete({ timeout: 30000 })
})
const number = args.join(" ")
if(!number) return message.channel.send("You haven't specified a number to purge").then(msg => {
msg.delete({ timeout: 30000 })
})
message.channel.bulkDelete(number).catch(console.error)
}
if (command === "rps") {
const options = [
"rock :shell: ",
"paper :newspaper2:",
"scissors :scissors: "
]
const option = options[Math.floor(Math.random() * options.length)]
message.channel.send(`You got ${option}`)
}
});
bot.login(config.token)