|
1 | | -import { token, botAdmins, prefixes } from './env'; |
2 | | -import CookiecordClient from 'cookiecord'; |
3 | | -import { Intents } from 'discord.js'; |
| 1 | +import { Client, GatewayIntentBits, Partials } from 'discord.js'; |
| 2 | +import { Bot } from './bot'; |
4 | 3 | import { getDB } from './db'; |
| 4 | +import { token } from './env'; |
5 | 5 | import { hookLog } from './log'; |
6 | 6 |
|
7 | | -import { AutoroleModule } from './modules/autorole'; |
8 | | -import { EtcModule } from './modules/etc'; |
9 | | -import { HelpThreadModule } from './modules/helpthread'; |
10 | | -import { PlaygroundModule } from './modules/playground'; |
11 | | -import { RepModule } from './modules/rep'; |
12 | | -import { TwoslashModule } from './modules/twoslash'; |
13 | | -import { HelpModule } from './modules/help'; |
14 | | -import { SnippetModule } from './modules/snippet'; |
15 | | -import { HandbookModule } from './modules/handbook'; |
16 | | -import { ModModule } from './modules/mod'; |
| 7 | +import { autoroleModule } from './modules/autorole'; |
| 8 | +import { etcModule } from './modules/etc'; |
| 9 | +import { handbookModule } from './modules/handbook'; |
| 10 | +import { helpModule } from './modules/help'; |
| 11 | +import { modModule } from './modules/mod'; |
| 12 | +import { playgroundModule } from './modules/playground'; |
| 13 | +import { repModule } from './modules/rep'; |
| 14 | +import { twoslashModule } from './modules/twoslash'; |
| 15 | +import { snippetModule } from './modules/snippet'; |
| 16 | +import { helpThreadModule } from './modules/helpthread'; |
17 | 17 |
|
18 | | -const client = new CookiecordClient( |
19 | | - { |
20 | | - botAdmins, |
21 | | - prefix: prefixes, |
| 18 | +const client = new Client({ |
| 19 | + partials: [ |
| 20 | + Partials.Reaction, |
| 21 | + Partials.Message, |
| 22 | + Partials.User, |
| 23 | + Partials.Channel, |
| 24 | + ], |
| 25 | + allowedMentions: { |
| 26 | + parse: ['users', 'roles'], |
22 | 27 | }, |
23 | | - { |
24 | | - partials: ['REACTION', 'MESSAGE', 'USER', 'CHANNEL'], |
25 | | - allowedMentions: { |
26 | | - parse: ['users', 'roles'], |
27 | | - }, |
28 | | - intents: new Intents([ |
29 | | - 'GUILDS', |
30 | | - 'GUILD_MESSAGES', |
31 | | - 'GUILD_MEMBERS', |
32 | | - 'GUILD_MESSAGE_REACTIONS', |
33 | | - 'DIRECT_MESSAGES', |
34 | | - ]), |
35 | | - }, |
36 | | -).setMaxListeners(Infinity); |
37 | | - |
38 | | -for (const mod of [ |
39 | | - AutoroleModule, |
40 | | - EtcModule, |
41 | | - HelpThreadModule, |
42 | | - PlaygroundModule, |
43 | | - RepModule, |
44 | | - TwoslashModule, |
45 | | - HelpModule, |
46 | | - SnippetModule, |
47 | | - HandbookModule, |
48 | | - ModModule, |
49 | | -]) { |
50 | | - client.registerModule(mod); |
51 | | -} |
| 28 | + intents: [ |
| 29 | + GatewayIntentBits.Guilds, |
| 30 | + GatewayIntentBits.GuildMessages, |
| 31 | + GatewayIntentBits.GuildMembers, |
| 32 | + GatewayIntentBits.GuildMessageReactions, |
| 33 | + GatewayIntentBits.DirectMessages, |
| 34 | + GatewayIntentBits.MessageContent, |
| 35 | + ], |
| 36 | +}).setMaxListeners(Infinity); |
52 | 37 |
|
53 | | -getDB(); // prepare the db for later |
| 38 | +getDB().then(() => client.login(token)); |
54 | 39 |
|
55 | | -client.login(token); |
56 | | -client.on('ready', () => { |
| 40 | +client.on('ready', async () => { |
| 41 | + const bot = new Bot(client); |
57 | 42 | console.log(`Logged in as ${client.user?.tag}`); |
58 | | - hookLog(client); |
| 43 | + await hookLog(client); |
| 44 | + |
| 45 | + for (const mod of [ |
| 46 | + autoroleModule, |
| 47 | + etcModule, |
| 48 | + helpThreadModule, |
| 49 | + playgroundModule, |
| 50 | + repModule, |
| 51 | + twoslashModule, |
| 52 | + helpModule, |
| 53 | + snippetModule, |
| 54 | + handbookModule, |
| 55 | + modModule, |
| 56 | + ]) { |
| 57 | + await mod(bot); |
| 58 | + } |
59 | 59 | }); |
60 | 60 |
|
61 | | -process.on('unhandledRejection', e => { |
62 | | - console.error('Unhandled rejection', e); |
| 61 | +client.on('error', error => { |
| 62 | + console.error(error); |
63 | 63 | }); |
| 64 | + |
| 65 | +if (process.env.NODE_ENV === 'production') { |
| 66 | + process.on('unhandledRejection', e => { |
| 67 | + console.error('Unhandled rejection', e); |
| 68 | + }); |
| 69 | +} |
0 commit comments