-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
138 lines (104 loc) · 3.47 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
'use strict';
const fs = require('fs'); //node.js native filesystem
require('dotenv').config();
require('./keepAwake/awake.js');
const Config = require("./settings.json");
const Discord = require('discord.js');
const client = new Discord.Client();
//Command handler
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// set a new item in the Collection
// with the key as the command name and the value as the exported module
client.commands.set(command.name, command);
}
//command handler end
//ready event
client.on('ready', () => {
console.log('Sucessfully logged in!');
console.log(" ");
console.log("====================================================================");
console.log(" ");
console.log("settings.json settings:");
console.log(" ");
console.log(Config);
client.user.setActivity(`${Config.prefix}help`, {type: "PLAYING"});
});
//ready event end
//DMs probably won't work cause I suck at JS lol
//Welcome message
client.on('guildMemberAdd', member => {
if(Config.welcomemsg == true) {
const channel = member.guild.channels.cache.find(ch => ch.name === 'member-log');
if (!channel) return;
channel.send(`Welcome to the server, ${member}! Make sure to read the rules to avoid punishment!`);
};
});
//commands
client.on('message', message => {
if (!message.content.startsWith(Config.prefix) || message.author.bot) return;
const args = message.content.slice(Config.prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
//commands end
//automod
client.on('message', message => {
if (Config.automod == true) {
//kick setting
if (Config.automodpunishment == "kick") {
for (var i = 0; i < Config.badwords.length; i++) {
if (message.content.includes(Config.badwords[i])) {
let member = message.member;
message
.delete({timeout: 1})
.catch(err => {
message.channel.send("I can't delete messages REEEEEEEEEEEEEEEEEE")
console.error(err)
});
member
.kick('Automod')
.then(() => {
message.channel.send(`Automod kicked ${message.author}, watch your mouth guys!`)
})
.catch(err => {
message.channel.send("Crazy coded me wrong so automod doesn't work lmao")
console.error(err);
});
break;
}
}
}
else if (Config.automodpunishment == "delete") {
for (var i = 0; i < Config.badwords.length; i++) {
if (message.content.includes(Config.badwords[i])) {
message
.delete({timeout: 1})
.catch(err => {
message.channel.send("Automod died lmao")
console.error(err);
});
}
}
};
};
});
//Rules agreeement
client.on('message', message => {
if(Config.nocommunity == true) {
if (message.channel.id === process.env.RULES_CHANNEL_ID && message.content === "I agree") {
let memberRole = message.guild.roles.cache.find(role => role.name === process.env.MEMBER_ROLE_NAME);
let member = message.member;
member.roles.add(memberRole).catch(console.error);
};
};
});
client.login();