Add logger function

This commit is contained in:
Christer Warén 2024-11-01 03:25:52 +02:00
parent cf93a9abf8
commit b6d07eb911
2 changed files with 43 additions and 2 deletions

5
src/functions/logger.ts Normal file
View File

@ -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');
}

View File

@ -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('InsID-Bot ' + process.env.npm_package_version);
console.log('Verkkopeliyhdistys Insomnia ry - Identity Bot'); console.log('Verkkopeliyhdistys Insomnia ry - Identity Bot');
console.log('(c)2024 Verkkopeliyhdistys Insomnia ry & Warén Group'); console.log('(c)2024 Verkkopeliyhdistys Insomnia ry & Warén Group');
console.log(''); 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.on('SIGINT', () => {
process.exit(); process.exit();