-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfarcyte.ts
72 lines (59 loc) · 1.83 KB
/
farcyte.ts
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
import { readdirSync } from 'fs';
import { Client, Intents, Collection, Interaction } from 'discord.js';
import { log } from './src/functions/utils';
import dotenv from 'dotenv';
import { Command } from './src/command';
import { CommandDeployer } from './deploy-commands';
class Farcyte {
private commands = new Collection<string, Command>();
commandFiles = readdirSync('./src/commands').filter((file: string) =>
file.endsWith('.ts'),
);
constructor(_commandDeployer: CommandDeployer = new CommandDeployer()) {
this.init();
}
client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES,
],
partials: ['CHANNEL'],
});
init() {
dotenv.config();
if (process.env.REST_REQUEST_TIMEOUT_MS) {
this.client.restRequestTimeout = parseInt(
process.env.REST_REQUEST_TIMEOUT_MS,
);
}
this.client.once('ready', () => {
console.log('Farcyte is awake!');
this.client.user?.setActivity('/find');
});
for (const file of this.commandFiles) {
const command = require(`./src/commands/${file}`);
this.commands.set(command.data.name, command);
}
this.client.on('interactionCreate', async (interaction: Interaction) => {
if (!interaction.isApplicationCommand()) {
return;
}
const command = this.commands.get(interaction.commandName);
if (!command) {
return;
}
try {
command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
});
this.client.login(process.env.TOKEN);
}
}
new Farcyte();