import Discord from 'discord.js'; import { config } from 'dotenv'; import chalk from 'chalk'; import pjson from '../package.json' assert { type: 'json' }; import InteractionHandler from './handlers/InteractionHandler.js'; import PresenceHandler from './handlers/PresenceHandler.js'; import APIService from './services/APIService.js'; config(); const TOKEN = process.env.TOKEN; const STATUS = process.env.STATUS; const STATUS_CONTENT = process.env.STATUS_CONTENT; const STATUS_TYPE = process.env.STATUS_TYPE; const CLIENT_ID = process.env.CLIENT_ID; const DEV_GUILD_ID = process.env.DEV_GUILD_ID; const LunaPresenceHandler = new PresenceHandler(STATUS_CONTENT, STATUS_TYPE, STATUS); const LunaInteractionHandler = await new InteractionHandler().init(TOKEN) .then((handler) => { console.log(`${chalk.green('Done:')} InteractionHandler initialized successfully`) return handler; }) .catch((e) => { console.log(`${chalk.red('Error:')} can not initialize InteractionHandler`) throw e; }); const LunaAPIService = await new APIService().init(); const Luna = new Discord.Client({ allowedMentions: { parse: [ 'users', 'roles' ], repliedUser: true }, autoReconnect: true, disabledEvents: [ 'TYPING_START' ], partials: [ Discord.Partials.Channel, Discord.Partials.GuildMember, Discord.Partials.Message, Discord.Partials.Reaction, Discord.Partials.User, Discord.Partials.GuildScheduledEvent ], intents: [ Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers, Discord.GatewayIntentBits.GuildBans, Discord.GatewayIntentBits.GuildEmojisAndStickers, Discord.GatewayIntentBits.GuildIntegrations, Discord.GatewayIntentBits.GuildWebhooks, Discord.GatewayIntentBits.GuildInvites, Discord.GatewayIntentBits.GuildVoiceStates, Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.GuildMessageReactions, Discord.GatewayIntentBits.GuildMessageTyping, Discord.GatewayIntentBits.DirectMessages, Discord.GatewayIntentBits.DirectMessageReactions, Discord.GatewayIntentBits.DirectMessageTyping, Discord.GatewayIntentBits.GuildScheduledEvents, Discord.GatewayIntentBits.MessageContent ], restTimeOffset: 0 }); const ASCIIHeader = [ ' ___ ___ ___ ___ ', ' /\\__\\ /\\__\\ /\\__\\ /\\ \\ ', ' /:/ / /:/ _/_ /:| _|_ /::\\ \\ ', ' /:/__/ /:/_/\\__\\ /::|/\\__\\ /::\\:\\__\\ ', ' \\:\\ \\ \\:\\/:/ / \\/|::/ / \\/\\::/ / ', ' \\:\\__\\ \\::/ / |:/ / /:/ / ', ' \\/__/ \\/__/ \\/__/ \\/__/ ' ].join('\n'); Luna.on(Discord.Events.ClientReady, async () => { console.clear(); console.log([ chalk.hex('#8EA6DB').bold(ASCIIHeader), chalk.hex('#6A54C9').bold.italic('Luna bot is ready\n\n'), `– Bot uses ${chalk.hex('#6A54C9').bold(Object.keys(pjson.dependencies).length)} packages\n` ].join('\n\n')); const link = Luna.generateInvite({ permissions: [ Discord.PermissionsBitField.Flags.Administrator ], scopes: [ 'bot' ] }); console.log([ chalk.blue.bold.underline('Bot invite link:'), chalk.blue.bold(link) ].join('\n')); await LunaPresenceHandler.init(Luna) .then((res) => { console.log(`${chalk.green('Done:')} PresenceHandler initialized successfully | status: ${res.status} | type: ${res.type} | content: ${res.content}`); }) .catch((e) => { console.log(`${chalk.red('Error:')} can not initialize PresenceHandler`); throw e; }); await LunaInteractionHandler.registerCommandsDev(CLIENT_ID, DEV_GUILD_ID); }); Luna.on(Discord.Events.InteractionCreate, async (interaction) => { await LunaInteractionHandler.handle(interaction, LunaAPIService); }); await Luna.login(TOKEN);