mirror of
https://github.com/cloudmaker97/FS25-Discord-Bot.git
synced 2025-12-06 08:28:33 +00:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import {Client, IntentsBitField} from 'discord.js';
|
|
import Configuration from "./Services/Configuration";
|
|
import Logging from "./Services/Logging";
|
|
import DiscordService from "./Services/DiscordEmbed";
|
|
|
|
const appLogger = Logging.getLogger();
|
|
const appConfig: Configuration = new Configuration();
|
|
const discordClient = new Client({
|
|
intents: [IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages]
|
|
});
|
|
|
|
/**
|
|
* Start the discord client and log in
|
|
* After that create a new DiscordService instance to start the server stats feed
|
|
*/
|
|
discordClient.login(appConfig.discord.botToken).then(() => {
|
|
appLogger.info(`Login successful to discord with token`);
|
|
});
|
|
|
|
/**
|
|
* Start the DiscordService and restart it if an error occurred
|
|
*/
|
|
function startDiscordService(): void {
|
|
try {
|
|
new DiscordService(discordClient);
|
|
} catch (exception) {
|
|
appLogger.error(`Restarting the discord service, an error occurred`, exception);
|
|
} finally {
|
|
setTimeout(() => {
|
|
startDiscordService();
|
|
}, 5000);
|
|
}
|
|
}
|
|
|
|
discordClient.on('ready', () => {
|
|
appLogger.info(`Discord client ready. Logged in as ${discordClient.user?.username}!`);
|
|
startDiscordService();
|
|
});
|