From b6d07eb911a66e346bdde8d3840655f907cd9d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Fri, 1 Nov 2024 03:25:52 +0200 Subject: [PATCH] Add logger function --- src/functions/logger.ts | 5 +++++ src/index.ts | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/functions/logger.ts diff --git a/src/functions/logger.ts b/src/functions/logger.ts new file mode 100644 index 0000000..5279de4 --- /dev/null +++ b/src/functions/logger.ts @@ -0,0 +1,5 @@ +export default function logger(area: string, text?: string){ + let date = new Date(); + console.log('[' + area + '] - ' + date.toISOString()); + if(text) console.log(text + '\n'); +} diff --git a/src/index.ts b/src/index.ts index f9a78ae..c5f6bb5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,47 @@ -import { Client as DiscordClient, Collection, IntentsBitField } from "discord.js"; +import Discord from "discord.js"; +import logger from "./functions/logger" console.log('InsID-Bot ' + process.env.npm_package_version); console.log('Verkkopeliyhdistys Insomnia ry - Identity Bot'); console.log('(c)2024 Verkkopeliyhdistys Insomnia ry & Warén Group'); console.log(''); -console.log('[Bot] Starting'); +logger('Bot', 'Starting'); + +const discordClient = new Discord.Client({ + intents: [ + Discord.GatewayIntentBits.GuildMembers, + Discord.GatewayIntentBits.Guilds + ] +}); + +discordClient.on('ready', () => { + logger('Discord Client', 'Ready'); +}); + +discordClient.on("interactionCreate", (interaction) => { + logger('Discord Client', 'Interaction Create'); +}); + +discordClient.on("guildMemberAdd", (member) => { + logger('Discord Client', 'Guild Member Add'); +}); + +discordClient.on("guildMemberRemove", (member) => { + logger('Discord Client', 'Guild Member Remove'); +}); + +discordClient.on("guildMemberUpdate", (oldMember, newMember) => { + logger('Discord Client', 'Guild Member Update'); +}); + +discordClient.login(process.env.DISCORD_TOKEN) + .then(() => { + logger('Discord Client', 'Login: Successful'); + }) + .catch(err => { + logger('Discord Client', 'Login: Failed'); + }); process.on('SIGINT', () => { process.exit();