diff --git a/.env.example b/.env.example index 3c7feaa..b6ee260 100644 --- a/.env.example +++ b/.env.example @@ -10,7 +10,7 @@ DISCORD_BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN DISCORD_APPLICATION_ID=YOUR_DISCORD_BOT_APPLICATION_ID # Optional: Set a YouTube cookie to reduce the chance of getting rate limited / 429 Too Many Requests -YOUTUBE_COOKIE= +YT_COOKIE= # Optional: Authentication tokens for botlist websites to automatically update server count, etc. # See /src/utils/postBotStats.js for more information diff --git a/README.md b/README.md index bbc319f..1a8921a 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,15 @@ This bot is open-source, and if you want to host it yourself, you can do so by f 6. Deploy slash commands via Discord API by running `npm run deploy`. This is required to make the commands accessible for Discord servers. 7. Run `npm start` to start the bot. If everything is configured and setup correctly, the bot should be online and ready to use. You will need to invite the bot to a server, see [Adding your bot to servers](https://discordjs.guide/preparations/adding-your-bot-to-servers.html#bot-invite-links) article for help. -Additional information: +### Additional information: - You can use `npm run deploy-pretty` and `npm run start-pretty` to get formatted, colorized output to console instead of JSON format. For this to work, you need the npm package `pino-pretty` installed, `npm install pino-pretty -g` to install it globally. - Logs are stored in `/logs` directory, you can configure the logging level to file and console under `loggerOptions` in `/src/config.js`. - +- For production use, I recommend using something like `pm2` to manage the process and automatically restart it if it crashes. Here's a simple setup for `pm2`: + - Install `pm2` globally: `npm install pm2 -g`. + - Start the bot with `pm2 start ./src/index.js --name "Cadence"`. + - Save the process list with `pm2 save`. + - To view logs with pino-pretty, run `pm2 logs 0 --out --raw | pino-pretty`. _Note: Does not work well in Windows PowerShell, use command prompt (cmd) to view logs with `pino-pretty` using same command if you are using `pm2`_. ## Get help and support 🛟 If you experience any issues, please open an issue on this repository or join the [Discord support server](https://discord.gg/cadence) for the Cadence bot. diff --git a/package-lock.json b/package-lock.json index d23b88a..588fb57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,14 +9,14 @@ "version": "2.2.3", "license": "MIT", "dependencies": { - "@discord-player/extractor": "^4.4.1-dev.0", + "@discord-player/extractor": "^4.4.1-dev.1", "@discordjs/opus": "^0.9.0", "@discordjs/rest": "^1.7.1", "@discordjs/voice": "^0.16.0", "discord-player": "^6.6.1", "discord.js": "^14.11.0", "dotenv": "^16.3.1", - "mediaplex": "^0.0.0", + "mediaplex": "^0.0.1", "node-os-utils": "^1.3.7", "pino": "^8.14.1", "yt-stream": "^1.4.8" @@ -41,9 +41,9 @@ "integrity": "sha512-U86em1cMtopXVuKFDxP8J2DcNOqwCAsYQ2tkzPoJvchsrezcI2cgvN3jtGt9FFECP3pLvSz96ZB9FOHZKG5Mqg==" }, "node_modules/@discord-player/extractor": { - "version": "4.4.1-dev.0", - "resolved": "https://registry.npmjs.org/@discord-player/extractor/-/extractor-4.4.1-dev.0.tgz", - "integrity": "sha512-DVc4B9wGi3OD8rF/s5r+SF+PQAXqIhyuKGQHs/bgKvdrcBiyP7Tqxr3hlcGt/ZtCifiW9Fp77uT7iRkl4gTsWA==", + "version": "4.4.1-dev.1", + "resolved": "https://registry.npmjs.org/@discord-player/extractor/-/extractor-4.4.1-dev.1.tgz", + "integrity": "sha512-mz9q5TE8M+e2ia5gvLCx6CBEU9JmsIxeA3xAqDYxaB61fTmPv6jnbZfKS1QpxbtrbfRzth+l2UHglS98jr7mPw==", "dependencies": { "file-type": "^16.5.4", "genius-lyrics": "^4.4.3", @@ -1965,33 +1965,33 @@ } }, "node_modules/mediaplex": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex/-/mediaplex-0.0.0.tgz", - "integrity": "sha512-pFg3SEQakC49Vem1vlUMptBDB5eiWH0v0jvR35oChtucjAtk3pKEqK0DqiQLShzLVvEnGfqXFIqYP+buFqkw5Q==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex/-/mediaplex-0.0.1.tgz", + "integrity": "sha512-zOkIGjnYYNUbQICUOAH+sJgLN674sXv7uRJMtNj8yLTh7Gjdvu2E/pBAS+vJwIDe92ZPcCF2H1Ovlz4WgWTbJw==", "engines": { "node": ">= 10" }, "optionalDependencies": { - "mediaplex-android-arm-eabi": "0.0.0", - "mediaplex-android-arm64": "0.0.0", - "mediaplex-darwin-arm64": "0.0.0", - "mediaplex-darwin-universal": "0.0.0", - "mediaplex-darwin-x64": "0.0.0", - "mediaplex-freebsd-x64": "0.0.0", - "mediaplex-linux-arm-gnueabihf": "0.0.0", - "mediaplex-linux-arm64-gnu": "0.0.0", - "mediaplex-linux-arm64-musl": "0.0.0", - "mediaplex-linux-x64-gnu": "0.0.0", - "mediaplex-linux-x64-musl": "0.0.0", - "mediaplex-win32-arm64-msvc": "0.0.0", - "mediaplex-win32-ia32-msvc": "0.0.0", - "mediaplex-win32-x64-msvc": "0.0.0" + "mediaplex-android-arm-eabi": "0.0.1", + "mediaplex-android-arm64": "0.0.1", + "mediaplex-darwin-arm64": "0.0.1", + "mediaplex-darwin-universal": "0.0.1", + "mediaplex-darwin-x64": "0.0.1", + "mediaplex-freebsd-x64": "0.0.1", + "mediaplex-linux-arm-gnueabihf": "0.0.1", + "mediaplex-linux-arm64-gnu": "0.0.1", + "mediaplex-linux-arm64-musl": "0.0.1", + "mediaplex-linux-x64-gnu": "0.0.1", + "mediaplex-linux-x64-musl": "0.0.1", + "mediaplex-win32-arm64-msvc": "0.0.1", + "mediaplex-win32-ia32-msvc": "0.0.1", + "mediaplex-win32-x64-msvc": "0.0.1" } }, "node_modules/mediaplex-android-arm-eabi": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-android-arm-eabi/-/mediaplex-android-arm-eabi-0.0.0.tgz", - "integrity": "sha512-cG/Iqebd0CNhf6JcFIejW3VKnYtstm36H73E46UNIemlm8/UOUW1ag8kzhC/4OlgLTThCdwfQG5LIqVI5rqxkA==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-android-arm-eabi/-/mediaplex-android-arm-eabi-0.0.1.tgz", + "integrity": "sha512-m3f3n1PaxSrCYMjaFsyP8Egyoz8q0dEgw8X6ivvbbXewjZSQ0xeLr31nzz/a2alDHLKs04jzyc/j1o8N6KwsuA==", "cpu": [ "arm" ], @@ -2004,9 +2004,9 @@ } }, "node_modules/mediaplex-android-arm64": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-android-arm64/-/mediaplex-android-arm64-0.0.0.tgz", - "integrity": "sha512-G9K6UPjetZAYNBrQ7ePLNGsyVnbuN90lC7m2Lcd8e2RVd0kxXlzXbSvT4NhnNgP4qEz6XrEzR1daJoHyIHf/Rw==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-android-arm64/-/mediaplex-android-arm64-0.0.1.tgz", + "integrity": "sha512-aHAyOSiTSLZmiyzpvrB6pfzViC8n43bNLfdvi9N6G37Yo2pSMZY0aH36ougVK87T/gjwNRo9xH4HkqD2G00nHQ==", "cpu": [ "arm64" ], @@ -2019,9 +2019,9 @@ } }, "node_modules/mediaplex-darwin-arm64": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-darwin-arm64/-/mediaplex-darwin-arm64-0.0.0.tgz", - "integrity": "sha512-TgzMVcx7P0cfRxqf2icC4KkFJg9PCnzwljBPWoxAvZLHktrod7BJTWj0UA065L3IedHBBQqzAq3XLH/4+ZFHPg==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-darwin-arm64/-/mediaplex-darwin-arm64-0.0.1.tgz", + "integrity": "sha512-rrpRknlz4MCEVT1p4KOhVzt3k9j3layRzE3clK1an/gOC0i1fzsuSMd+8RCPAfvrIOM8XCRCSulhzE8iEGmc8Q==", "cpu": [ "arm64" ], @@ -2034,9 +2034,9 @@ } }, "node_modules/mediaplex-darwin-universal": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-darwin-universal/-/mediaplex-darwin-universal-0.0.0.tgz", - "integrity": "sha512-avLsD2J8HrYv7hgHMFVUSekgr9GMEp31cG57HlfhSF/jPZlZXj70pb0YHE0SW9/CG44eVIdZsSSC8XmWB8iCug==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-darwin-universal/-/mediaplex-darwin-universal-0.0.1.tgz", + "integrity": "sha512-5K9aMef4ZZv2j8Tav5W5TSHaX2mOAa7ZAQ8/f1YvMnDBsxHYyTb2wq1k01l6g56gnVKT0wmzRMXOoBJ0+cK+ng==", "optional": true, "os": [ "darwin" @@ -2046,9 +2046,9 @@ } }, "node_modules/mediaplex-darwin-x64": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-darwin-x64/-/mediaplex-darwin-x64-0.0.0.tgz", - "integrity": "sha512-JUcgCkXE2fmFo6U6RPs2koRH5XKKRtiP1irnGBuB5282DhSoB90Mb8ZdluOLQYpsAEBSDtcqkLWNoyl56Gbp7Q==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-darwin-x64/-/mediaplex-darwin-x64-0.0.1.tgz", + "integrity": "sha512-ojqf2mzsip1YhavdfEnZjJ8b7N+QMIbFNp4i8wT6Xl5RrHsrqOYcjmU0mgZYJ+vCCUdN1KymRqAub1mkyMK+8g==", "cpu": [ "x64" ], @@ -2061,9 +2061,9 @@ } }, "node_modules/mediaplex-freebsd-x64": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-freebsd-x64/-/mediaplex-freebsd-x64-0.0.0.tgz", - "integrity": "sha512-U10wDBUs2KiVByMZ1VX+QAruNPgABQI+AMZJnb5hIYcqrWM8r9/1IdPzn3jWK6gApUYMLFDJmYGh01YLaycUiQ==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-freebsd-x64/-/mediaplex-freebsd-x64-0.0.1.tgz", + "integrity": "sha512-4wlVHpakZXN8rmM1jCetecy6xuzTMGitYFQxpqwx3YWoWz/HlpbTq+U817av0WXdYb1p1Vs177RuFMM97mVsoQ==", "cpu": [ "x64" ], @@ -2076,9 +2076,9 @@ } }, "node_modules/mediaplex-linux-arm-gnueabihf": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-linux-arm-gnueabihf/-/mediaplex-linux-arm-gnueabihf-0.0.0.tgz", - "integrity": "sha512-f1gIHlbWE9/0Qt5GEvY2Vwgqo4k7iNWmZkI2XmLApX/QJ4OVU1UFGG0HyY8rVXQd5iLuxbtPwxkLBWSW+eIkXg==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-linux-arm-gnueabihf/-/mediaplex-linux-arm-gnueabihf-0.0.1.tgz", + "integrity": "sha512-mFbTzlnAiS9S+pCK56OzIkIiiNeVVEKfqi3lSVnkqjlpv2t3n8nO47nPqzE8pDqAFcxjQwq/+fbLxKVmN6+kDw==", "cpu": [ "arm" ], @@ -2091,9 +2091,9 @@ } }, "node_modules/mediaplex-linux-arm64-gnu": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-linux-arm64-gnu/-/mediaplex-linux-arm64-gnu-0.0.0.tgz", - "integrity": "sha512-Gr+Dw9ObUkg0U3uckTJkn19kxs+LHhcSgM3v92gDCXBFu2JzkidoRzpwYRzVtSuHgjBQQfv+EU3JgszzI9UWEg==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-linux-arm64-gnu/-/mediaplex-linux-arm64-gnu-0.0.1.tgz", + "integrity": "sha512-MAqHlUCmw+LIR6NTByKU84V0dPCsg/ODvy/FNTGafxmfHkLsrM/yqzwVH4LlqRO8A/v12w/BLnepdxhooF5QaQ==", "cpu": [ "arm64" ], @@ -2106,9 +2106,9 @@ } }, "node_modules/mediaplex-linux-arm64-musl": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-linux-arm64-musl/-/mediaplex-linux-arm64-musl-0.0.0.tgz", - "integrity": "sha512-SRajRO2bXudnYICFpFAr3J/OKrWMDi7RRHn90RcfLkUnE3JsiwQHeKJhW6gDj3SPcgBODMgfR5BrpMkLGRmaJQ==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-linux-arm64-musl/-/mediaplex-linux-arm64-musl-0.0.1.tgz", + "integrity": "sha512-mEvZzFy82AxI6vXmQgM9t3HVdMGQCQEdY1ivNV2t3M2MhKlk1b9TJ882181Z2CQQRcKU1QUGimmHzpFhuh8Fvw==", "cpu": [ "arm64" ], @@ -2121,9 +2121,9 @@ } }, "node_modules/mediaplex-linux-x64-gnu": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-linux-x64-gnu/-/mediaplex-linux-x64-gnu-0.0.0.tgz", - "integrity": "sha512-RbfMUCknCBCJv73HiyWV+nMeLCAvTMn/xlaV2vbhtTYFAWAheOvW4lSzfkBZbeZ4LSeiRnCv+5GOMAtesRgVnw==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-linux-x64-gnu/-/mediaplex-linux-x64-gnu-0.0.1.tgz", + "integrity": "sha512-Ia8ELm6l8ZOGUy9hq4X7Y7DrAo9g4lVhT+o0TblpJxoB4odhCvQdfOlkV686OIRsi0SjVpWU92grZyukxGG4rw==", "cpu": [ "x64" ], @@ -2136,9 +2136,9 @@ } }, "node_modules/mediaplex-linux-x64-musl": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-linux-x64-musl/-/mediaplex-linux-x64-musl-0.0.0.tgz", - "integrity": "sha512-GBxA3j+2bdzZAhVtR4QPUhoULMNwfHwNvgyycZS8vmpjLcDGXieEBCc72eFGHOzNFLzzJ0BvEO8R4R/rZ5VzXg==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-linux-x64-musl/-/mediaplex-linux-x64-musl-0.0.1.tgz", + "integrity": "sha512-TiEZhbiciA6bjps5WQNa6Z1M7vsIZ24Vrj2w98ZLQIS7n7zv33r6kM8/EzQjbcC0IRD7EuS+Xvd2NK0Wcr1/yQ==", "cpu": [ "x64" ], @@ -2151,9 +2151,9 @@ } }, "node_modules/mediaplex-win32-arm64-msvc": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-win32-arm64-msvc/-/mediaplex-win32-arm64-msvc-0.0.0.tgz", - "integrity": "sha512-7CkVgz2N47VcLIffEVqdCgBvuUOGE/qNOhAY13Qp/qlbNHlhPLKPiRg8mwZaJ0Js5dsJRqXWZ8+u47PD6twA3A==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-win32-arm64-msvc/-/mediaplex-win32-arm64-msvc-0.0.1.tgz", + "integrity": "sha512-xWk2PEMlmndQL+8AQ3uNiJJUQqv4JZTG6SPKieK7G3bUdH5gGNzWEhqQr3+D0r/ACBy2fstG0SCPpx3iRG71aQ==", "cpu": [ "arm64" ], @@ -2166,9 +2166,9 @@ } }, "node_modules/mediaplex-win32-ia32-msvc": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-win32-ia32-msvc/-/mediaplex-win32-ia32-msvc-0.0.0.tgz", - "integrity": "sha512-6WbRf8RJ3isEbCjgnc0Z+4w3q+1sAEFQO6vU4ucBpiWWxHIRKUP3ykiVAobAoGw9nsG8UUmDbPliWL0RFcVzDg==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-win32-ia32-msvc/-/mediaplex-win32-ia32-msvc-0.0.1.tgz", + "integrity": "sha512-SR46w2Ns0X+vWStZUGBqcTzelPUxYYiph2SFLLAlMZ1TpIx8Txg/QA6Ob4gRBH8ku4Sm8DUKuOBGhs3v6lxwsw==", "cpu": [ "ia32" ], @@ -2181,9 +2181,9 @@ } }, "node_modules/mediaplex-win32-x64-msvc": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/mediaplex-win32-x64-msvc/-/mediaplex-win32-x64-msvc-0.0.0.tgz", - "integrity": "sha512-Uc7L7b2yeHGmFQ+kRz2F3Dr36/xI/H00LUERwmLOVRaac8rMLhvPhWBpxVmwLMD11wGGnYMtbZLuzROtBMZunw==", + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mediaplex-win32-x64-msvc/-/mediaplex-win32-x64-msvc-0.0.1.tgz", + "integrity": "sha512-ZE3gEn9onjLpZr4qoRa7scEZTJTLGleFiJ0kOfmi76ym7HlDlXgtWrtivnm3drHt/zS9ScC0pp+4r+V5xzIzuw==", "cpu": [ "x64" ], diff --git a/package.json b/package.json index e0a7749..2f4e242 100644 --- a/package.json +++ b/package.json @@ -26,14 +26,14 @@ "eslint": "eslint ./" }, "dependencies": { - "@discord-player/extractor": "^4.4.1-dev.0", + "@discord-player/extractor": "^4.4.1-dev.1", "@discordjs/opus": "^0.9.0", "@discordjs/rest": "^1.7.1", "@discordjs/voice": "^0.16.0", "discord-player": "^6.6.1", "discord.js": "^14.11.0", "dotenv": "^16.3.1", - "mediaplex": "^0.0.0", + "mediaplex": "^0.0.1", "node-os-utils": "^1.3.7", "pino": "^8.14.1", "yt-stream": "^1.4.8" diff --git a/src/utils/deploySlashCommands.js b/src/utils/deploySlashCommands.js index ecd47d6..a4ac94e 100644 --- a/src/utils/deploySlashCommands.js +++ b/src/utils/deploySlashCommands.js @@ -24,20 +24,20 @@ for (const folder of commandFolders) { const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN); (async () => { + if (!process.env.DISCORD_APPLICATION_ID || !process.env.DISCORD_BOT_TOKEN) { + logger.error('Missing required environment variables for deployment.'); + logger.error('Provide valid DISCORD_APPLICATION_ID and DISCORD_BOT_TOKEN in .env file.'); + } + try { logger.info('DEPLOYING BOT SLASH COMMANDS'); logger.info( - slashCommands.map((command) => { - return command.name; - }), + slashCommands.map((command) => command.name), 'Bot commands found:' ); logger.info('Started refreshing application (/) bot commands.'); - await rest.put(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), { - body: slashCommands - }); - + await refreshCommands(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), slashCommands); logger.info('Successfully refreshed application (/) bot commands.'); } catch (error) { logger.error(error, 'Failed to refresh application (/) bot commands.'); @@ -46,22 +46,28 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN) try { logger.info('DEPLOYING SYSTEM SLASH COMMANDS'); logger.info( - systemCommands.map((systemCommand) => { - return systemCommand.name; - }), + systemCommands.map((systemCommand) => systemCommand.name), 'System commands found:' ); logger.info('Started refreshing application (/) system commands.'); - for (const systemGuildId of systemOptions.systemGuildIds) { - logger.info(`Refreshing system commands for guild id ${systemGuildId}.`); - await rest.put(Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, systemGuildId), { - body: systemCommands - }); - } - + const systemGuildIds = systemOptions.systemGuildIds; + await Promise.all( + systemGuildIds.map((systemGuildId) => { + logger.info(`Refreshing system commands for guild id: ${systemGuildId}.`); + refreshCommands( + Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, systemGuildId), + systemCommands + ); + }) + ); logger.info('Successfully refreshed application (/) system commands.'); } catch (error) { logger.error(error, 'Failed to refresh application (/) system commands.'); + logger.error('Make sure the bot is in the system guilds provided.'); } })(); + +async function refreshCommands(route, commands) { + await rest.put(route, { body: commands }); +} diff --git a/src/utils/factory/createClient.js b/src/utils/factory/createClient.js index da7b3bb..aff4d38 100644 --- a/src/utils/factory/createClient.js +++ b/src/utils/factory/createClient.js @@ -2,33 +2,37 @@ const logger = require('../../services/logger'); const Discord = require('discord.js'); exports.createClient = async () => { - logger.debug('Creating Discord.js client...'); + try { + logger.info('Creating Discord.js client...'); - const client = new Discord.Client({ - intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates], - makeCache: Discord.Options.cacheWithLimits({ - ...Discord.Options.DefaultMakeCacheSettings, - MessageManager: 25, - ThreadManager: 25, - PresenceManager: 0, - ReactionManager: 0, - GuildMemberManager: { - maxSize: 50, - keepOverLimit: (member) => member.id === client.user.id + const client = new Discord.Client({ + intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates], + makeCache: Discord.Options.cacheWithLimits({ + ...Discord.Options.DefaultMakeCacheSettings, + MessageManager: 25, + ThreadManager: 25, + PresenceManager: 0, + ReactionManager: 0, + GuildMemberManager: { + maxSize: 50, + keepOverLimit: (member) => member.id === client.user.id + } + }), + sweepers: { + ...Discord.Options.DefaultSweeperSettings, + messages: { + interval: 3600, + lifetime: 1800 + }, + users: { + interval: 3600, + filter: () => (user) => user.id !== client.user.id + } } - }), - sweepers: { - ...Discord.Options.DefaultSweeperSettings, - messages: { - interval: 3600, - lifetime: 1800 - }, - users: { - interval: 3600, - filter: () => (user) => user.id !== client.user.id - } - } - }); - - return client; + }); + return client; + } catch (error) { + logger.error('Failed to create Discord.js client', error); + throw error; + } }; diff --git a/src/utils/factory/createPlayer.js b/src/utils/factory/createPlayer.js index cc3c39a..bde8841 100644 --- a/src/utils/factory/createPlayer.js +++ b/src/utils/factory/createPlayer.js @@ -3,38 +3,43 @@ const { Player, onBeforeCreateStream } = require('discord-player'); const { stream } = require('yt-stream'); exports.createPlayer = async (client) => { - logger.debug('Creating discord-player player...'); + try { + logger.info('Creating discord-player player...'); - const player = new Player(client, { - useLegacyFFmpeg: false, - ytdlOptions: { - quality: 'highestaudio', - highWaterMark: 1 << 25, - requestOptions: { - headers: { - cookie: process.env.YOUTUBE_COOKIE || '' + const player = new Player(client, { + useLegacyFFmpeg: false, + ytdlOptions: { + quality: 'highestaudio', + highWaterMark: 1 << 25, + requestOptions: { + headers: { + cookie: process.env.YT_COOKIE || '' + } } } - } - }); + }); - onBeforeCreateStream(async (track) => { - if (track.source === 'youtube') { - return ( - await stream(track.url, { - type: 'audio', - quality: 'high', - highWaterMark: 1 << 25, - cookie: process.env.YOUTUBE_COOKIE || '' - }) - ).stream; - } + onBeforeCreateStream(async (track) => { + if (track.source === 'youtube') { + return ( + await stream(track.url, { + type: 'audio', + quality: 'high', + highWaterMark: 1 << 25, + cookie: process.env.YT_COOKIE || '' + }) + ).stream; + } - return null; - }); + return null; + }); - await player.extractors.loadDefault(); - logger.debug(`discord-player loaded dependencies:\n${player.scanDeps()}`); + await player.extractors.loadDefault(); + logger.debug(`discord-player loaded dependencies:\n${player.scanDeps()}`); - return player; + return player; + } catch (error) { + logger.error('Failed to create discord-player player', error); + throw error; + } }; diff --git a/src/utils/registerClientCommands.js b/src/utils/registerClientCommands.js index 5b54adc..2a10447 100644 --- a/src/utils/registerClientCommands.js +++ b/src/utils/registerClientCommands.js @@ -5,16 +5,23 @@ const { Collection } = require('discord.js'); exports.registerClientCommands = (client) => { logger.debug('Registering client commands...'); - client.commands = new Collection(); + const commandFolders = fs.readdirSync(path.resolve('./src/commands')); for (const folder of commandFolders) { - const commandFiles = fs.readdirSync(path.resolve(`./src/commands/${folder}`)).filter((file) => file.endsWith('.js')); + const commandFiles = fs + .readdirSync(path.resolve(`./src/commands/${folder}`)) + .filter((file) => file.endsWith('.js')); for (const file of commandFiles) { - logger.debug(`Registering command ${folder}/${file}...`); - const command = require(`../commands/${folder}/${file}`); - client.commands.set(command.data.name, command); + try { + logger.debug(`Registering command ${folder}/${file}...`); + const command = require(`../commands/${folder}/${file}`); + client.commands.set(command.data.name, command); + } catch (error) { + logger.error(`Error registering command ${folder}/${file}: ${error.message}`); + throw error; + } } } };