This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
97 lines (88 loc) · 3.71 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
const { Client, Intents, MessageEmbed, Collection, Options } = require('discord.js');
const client = new Client({
makeCache: Options.cacheWithLimits({
ApplicationCommandManager: Infinity,
ChannelManager: Infinity,
GuildManager: Infinity,
GuildMemberManager: Infinity,
UserManager: Infinity,
}),
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
const { readdirSync } = require("fs");
const chalk = require('chalk')
const config = require('./data/config.json')
const { Database } = require('beta.db')
const db = new Database('./data/config.json')
client.login(config.token);
// --------------------------------------------
client.commands = new Collection();
const commandFiles = readdirSync('./commands').filter(file => file.endsWith('.js'));
console.log(chalk.red('------------- LOADING COMMANDS -------------'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
console.log(chalk.blue(command.data.name + ' LOADED'));
}
console.log(chalk.red('-------------- LOADING EVENTS --------------'));
const eventFiles = readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
console.log(chalk.blue(event.name + ' LOADED'));
}
console.log(chalk.red('--------------------------------------------'));
client.on('guildCreate', async guild => {
let JoinEmbed = new MessageEmbed()
.setDescription('**<:space:874678195843125278><:right:874690882417360986> A New Guild Has Been Submited**')
.setAuthor({ name: guild.name, iconURL: guild.iconURL({ dynamic: true }) })
.setColor('#0fe694')
client.channels.cache.get(config.BOT_LOG).send({ embeds: [JoinEmbed] });
});
// --------------------------------------------
client.on('guildDelete', async guild => {
let LeftEmbed = new MessageEmbed()
.setDescription('**<:space:874678195843125278><:right:874690882417360986> A Guild Has Been Removed **')
.setAuthor({ name: guild.name, iconURL: guild.iconURL({ dynamic: true }) })
.setColor('#ff0000')
client.channels.cache.get(config.BOT_LOG).send({ embeds: [LeftEmbed] });
});
// --------------------------------------------
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
if (interaction.guild) {
await command.execute(interaction, client);
db.add('USAGE', 1)
client.channels.cache.get(config.ACTION_LOG).send('```\n' + `${interaction.commandName} Triggerd In ${interaction.guild.name} | ${interaction.channel.name} By ${interaction.user.tag}` + '\n```')
} else {
return interaction.reply({ content: 'Interactions Only Works In Servers', ephemeral: true });
}
} catch (error) {
console.error(error);
client.channels.cache.get(config.ERROR).send('```\n' + error + '\n```')
return interaction.reply({ content: `There was an error while executing this command!\nAsk Developers In : ${config.supportserver}`, ephemeral: true });
}
});
// --------------------------------------------
process.on('unhandledRejection', err => {
console.log(err);
var errembed = new MessageEmbed()
.setTitle(':warning: New Error')
.setColor('YELLOW')
.addFields(
{ name: ':pushpin: Type: ', value: `\`\`\`${err.name + "".split("", 150).join("") || "N/A"}\`\`\`` },
{
name: ':page_with_curl: Reason: ',
value: `\`\`\`${err.message + "".split("", 150).join("") || "N/A"}\`\`\``
},
)
.setTimestamp()
// client.channels.cache.get(config.ERROR).send({ embeds: [errembed] })
});