This repository has been archived on 2026-01-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Lunaris/index.js
2023-07-02 01:57:55 +02:00

82 lines
2.6 KiB
JavaScript

const { Client, GatewayIntentBits } = require('discord.js');
const process = require('dotenv').config();
const { getVoiceConnection } = require('@discordjs/voice');
const { registerCommands } = require('./utils/registerCommands');
const { playCommand } = require('./commands/play');
const { queueCommand } = require('./commands/queue');
const { stopCommand } = require('./commands/stop');
const { pauseCommand, unpauseCommand } = require('./commands/pauseResume');
const { toggleLoopCommand } = require('./commands/loop');
const { skipCommand } = require('./commands/skip');
const { leaveCommand } = require('./commands/leave');
const { previousCommand } = require('./commands/previous');
const { ReAuth } = require('./reAuthenticate');
const ConsolerLogger = require('./utils/logger');
const { clientId } = process.parsed;
const { token } = process.parsed;
const logger = new ConsolerLogger();
const botClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildIntegrations,
],
});
botClient.on('ready', async () => {
logger.info(`Logged in as ${botClient.user.tag}!`);
botClient.user.setActivity('League of Legends', 0);
await registerCommands(clientId, token);
});
botClient.on('voiceStateUpdate', (oldState) => {
const voiceChannel = oldState.channel;
if (voiceChannel && voiceChannel.members.size === 1) {
const connection = getVoiceConnection(voiceChannel.guild.id);
if (connection) {
connection.disconnect();
connection.destroy();
}
}
});
botClient.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'play') {
await playCommand(interaction, botClient);
} else if (commandName === 'queue') {
await queueCommand(interaction);
} else if (commandName === 'pause') {
await pauseCommand(interaction);
} else if (commandName === 'resume') {
await unpauseCommand(interaction);
} else if (commandName === 'loop') {
await toggleLoopCommand(interaction);
} else if (commandName === 'stop') {
await stopCommand(interaction);
} else if (commandName === 'leave') {
await leaveCommand(interaction);
} else if (commandName === 'skip') {
await skipCommand(interaction);
} else if (commandName === 'previous') {
await previousCommand(interaction);
}
});
botClient.on('messageCreate', async (message) => {
if (message.content === 'reauth') {
await ReAuth();
}
});
botClient.login(token);
module.exports.botClient = { botClient };