-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.ts
35 lines (29 loc) · 822 Bytes
/
index.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
import TelegramBot from 'node-telegram-bot-api';
import { CommandHandler } from './handlers/CommandHandlers';
import config from './config';
import dotenv from 'dotenv';
dotenv.config();
const bot = new TelegramBot(`${process.env.TOKEN_BOT}`, { polling: true });
const commandHandler = new CommandHandler(bot, config);
declare global {
var handler: CommandHandler;
}
global.handler = commandHandler;
async function startBot() {
try {
dotenv.config();
await commandHandler.loadCommands();
console.log("Bot started successfully!");
process.once('SIGINT', () => {
bot.stopPolling();
process.exit(0);
});
process.once('SIGTERM', () => {
bot.stopPolling();
process.exit(0);
});
} catch (error) {
console.error("Error starting bot:", error);
}
}
startBot();