-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
70 lines (63 loc) · 2.21 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
const {Intents, Client, Permissions } = require('discord.js')
const {sendJoke} = require("./handlers/jokehandler");
const {sendQuote} = require("./handlers/quotehandler");
const {sendGIF} = require("./handlers/gifhandler");
const {banMember, kickMember} = require("./handlers/GuildMemberHandler");
const {checkMemberPermissions} = require("./utils/permissions");
const {deleteMessages} = require("./handlers/messagehandler");
const express = require('express');
const client = new Client({ intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILDS ]});
const server = express();
server.all('/', (req, res)=>{
res.send('Your bot is alive!')
})
server.listen(3000, ()=>{console.log("Server is Ready!")});
client.login(process.env.DISCORD_TOKEN);
client.on('ready', readyDiscord);
client.on('message', gotMessage)
function readyDiscord(){
console.log('DISCORD READY');
}
function gotMessage(msg){
handleCommands(msg);
}
function handleCommands(msg){
if(!msg.content.startsWith('!')){
return;
}
let content = msg.content.match(/(?:[^\s"]+|"[^"]*")+/g);
let commandToken = content[0];
content.shift();
switch (commandToken) {
case '!gif':
sendGIF(msg, content);
break;
case '!quote':
sendQuote(msg);
break;
case '!joke':
sendJoke(msg, content);
break;
case '!delete':
if (!checkMemberPermissions(msg.member, Permissions.FLAGS.MANAGE_MESSAGES)){
msg.reply("You do not have permission to delete messages");
return;
}
deleteMessages(msg.channel, content) ;
break;
case '!ban':
if (!checkMemberPermissions(msg.member, Permissions.FLAGS.BAN_MEMBERS)){
msg.reply("You do not have permission to ban members");
return;
}
banMember(msg);
break;
case '!kick':
if (!checkMemberPermissions(msg.member, Permissions.FLAGS.KICK_MEMBERS)){
msg.reply("You do not have permission to kick members");
return;
}
kickMember(msg);
break;
}
}