forked from ASEAN-Build-The-Earth/Merlion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
118 lines (100 loc) · 3.97 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
/* * * * * * * * * * * * * * * * * * * * * * * * *\
*
* FileName : index.js
* Author : Association of Southeast Asian Nations Build The Earth
* CreateTime : 15-5-2021
* Organization : https://github.com/ASEAN-Build-The-Earth
* Description : Merlion discord bot core file
* FileType : JS File
*
\* * * * * * * * * * * * * * * * * * * * * * * * */
const fs = require('fs');
const { Client, Intents, Collection, } = require('discord.js');
const { prefix } = require('./data/config.json');
const { token } = require("./data/auth.json")
const client = new Client({
intents: [
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_VOICE_STATES
] //,
//partials: ["CHANNEL"]
});
client.commands = new Collection();
const commandFolders = fs.readdirSync('./commands');
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.name, command);
}
// ===== TEMPOLARY SPECIAL FILE SEARCHING =====
// - it search for commands in ./commands/Fun/Images since the code above dont support 2nd folder step.
const funImageDirectory = "./commands/Fun/Images";
try
{
if (fs.existsSync(funImageDirectory))
{
console.log("Image directory exists")
const funImagesFile = fs.readdirSync(funImageDirectory).filter(file => file.endsWith('.js'));
for (const file of funImagesFile)
{
const specialCommand = require(`${funImageDirectory}/${file}`);
client.commands.set(specialCommand.name, specialCommand);
}
}
}
catch(error)
{
console.log("Cannot find Images directory:\n" + error);
}
}
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity(`YOU`, {
type: "WATCHING",
});
});
client.on('messageCreate', message => {
// === All the autoresponders ===
if (message.content === "<@850730172630302720>" || message.content === "<@!850730172630302720>") {
message.reply(`Hi ${message.author}, My Prefix is \`${prefix}\`!`)
}
if (message.content.toLowerCase() === 'hi') {
return message.reply('Hi :)');
}
if (message.content.toLowerCase() === 'xbox') {
return message.reply('Is Sus');
}
if (message.content.toLowerCase() === 'phats') {
return message.reply('https://media.discordapp.net/attachments/832603438285062164/869838594859237418/render_2021-07-21_15.32.09.gif');
}
if (message.content.toLowerCase() === 'how to join') {
return message.reply('Please read <#789012857798000690>');
}
if (message.content.toLowerCase() === 'how do i join') {
return message.reply('Please read <#789012857798000690>');
}
if (!message.content.startsWith(prefix)) return;
// === Message and command handler ====
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName) ||
client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
try {
return command.execute(message, args, client);
} catch (error) {
console.error(error);
const ErrorEmbed = new Discord.MessageEmbed()
.setColor("#ffb7c5")
.setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL({ dynamic: true })}`)
.addFields({ name: "ERR!", value: "Oops! I can't execute this command!" }, );
return message.reply({ embeds: [ErrorEmbed] });
}
});
client.login(token)