diff --git a/bot/bot.log b/bot/bot.log index b177d6d..0e99b1d 100644 --- a/bot/bot.log +++ b/bot/bot.log @@ -538,3 +538,125 @@ Ready! Logged in as AsepXiaoQin#6954 FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg [2026-02-16T08:36:47.798Z] Alarm scheduled at 30 3 * * * Alarm scheduled at 30 3 * * * +[2026-02-16T08:38:33.364Z] Searching via play-dl for: bawa dia kembali +Searching via play-dl for: bawa dia kembali +[2026-02-16T08:38:34.309Z] Found URL via play-dl: https://www.youtube.com/watch?v=j2U08vZSHGA +Found URL via play-dl: https://www.youtube.com/watch?v=j2U08vZSHGA +SyntaxError: Unexpected token 'D', "Deprecated"... is not valid JSON + at JSON.parse () + at ChildProcess. (/home/ubuntu/executor/workspace/bot/node_modules/@distube/yt-dlp/dist/index.js:84:36) + at ChildProcess.emit (node:events:518:28) + at maybeClose (node:internal/child_process:1101:16) + at ChildProcess._handle.onexit (node:internal/child_process:304:5) +[2026-02-16T08:39:01.802Z] Uncaught Exception: Unexpected token 'D', "Deprecated"... is not valid JSON +Uncaught Exception: Unexpected token 'D', "Deprecated"... is not valid JSON +SyntaxError: Unexpected token 'D', "Deprecated"... is not valid JSON + at JSON.parse () + at ChildProcess. (/home/ubuntu/executor/workspace/bot/node_modules/@distube/yt-dlp/dist/index.js:84:36) + at ChildProcess.emit (node:events:518:28) + at maybeClose (node:internal/child_process:1101:16) + at ChildProcess._handle.onexit (node:internal/child_process:304:5) +[2026-02-16T08:39:13.543Z] Playing local file independently: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +Playing local file independently: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +[dotenv@17.3.1] injecting env (4) from .env -- tip: 🤖 agentic secret storage: https://dotenvx.com/as2 +[2026-02-16T08:46:39.114Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T08:46:39.571Z] Bot berhasil login! +[2026-02-16T08:46:39.572Z] Ready! Logged in as AsepXiaoQin#6954 +[2026-02-16T08:46:39.572Z] FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +Bot berhasil login! +Ready! Logged in as AsepXiaoQin#6954 +FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +[2026-02-16T08:46:39.716Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * +[dotenv@17.3.1] injecting env (4) from .env -- tip: ⚙️ write to custom object with { processEnv: myObject } +[2026-02-16T08:49:12.201Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T08:49:13.692Z] Bot berhasil login! +Bot berhasil login! +[2026-02-16T08:49:13.697Z] Ready! Logged in as AsepXiaoQin#6954 +Ready! Logged in as AsepXiaoQin#6954 +[2026-02-16T08:49:13.700Z] FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +[2026-02-16T08:49:13.762Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * +[dotenv@17.3.1] injecting env (4) from .env -- tip: 🛡️ auth for agents: https://vestauth.com +[2026-02-16T08:49:24.070Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T08:49:24.735Z] Bot berhasil login! +[2026-02-16T08:49:24.735Z] Ready! Logged in as AsepXiaoQin#6954 +[2026-02-16T08:49:24.736Z] FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +Bot berhasil login! +Ready! Logged in as AsepXiaoQin#6954 +FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +[2026-02-16T08:49:24.780Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * +[2026-02-16T08:55:08.549Z] Searching via play-dl for: bawa dia kembali +Searching via play-dl for: bawa dia kembali +[2026-02-16T08:55:08.995Z] Found URL via play-dl: https://www.youtube.com/watch?v=dq2i49uwEJg +Found URL via play-dl: https://www.youtube.com/watch?v=dq2i49uwEJg +[2026-02-16T08:55:09.826Z] Play Error: Invalid URL +Play Error: Invalid URL +[2026-02-16T08:55:21.145Z] Searching via play-dl for: https://on.soundcloud.com/ORjsl2DMlAGkmIXfel +Searching via play-dl for: https://on.soundcloud.com/ORjsl2DMlAGkmIXfel +[2026-02-16T08:55:55.931Z] Searching via play-dl for: https://youtu.be/82A9lCx2XgY?si=DfeROWrUs5xUwclK +Searching via play-dl for: https://youtu.be/82A9lCx2XgY?si=DfeROWrUs5xUwclK +[2026-02-16T08:55:56.200Z] Found URL via play-dl: https://www.youtube.com/watch?v=82A9lCx2XgY +Found URL via play-dl: https://www.youtube.com/watch?v=82A9lCx2XgY +[2026-02-16T08:55:56.747Z] Play Error: Invalid URL +Play Error: Invalid URL +[2026-02-16T08:56:24.330Z] Searching via play-dl for: https://open.spotify.com/track/3qhlB30KknSejmIvZZLjOD?si=2NMmRTKnQJ-fMh9OmWm9Bw +Searching via play-dl for: https://open.spotify.com/track/3qhlB30KknSejmIvZZLjOD?si=2NMmRTKnQJ-fMh9OmWm9Bw +[2026-02-16T08:56:35.574Z] Playing local file independently: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +Playing local file independently: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +[dotenv@17.3.1] injecting env (4) from .env -- tip: 🔐 encrypt with Dotenvx: https://dotenvx.com +[2026-02-16T09:03:26.677Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T09:03:27.142Z] Bot berhasil login! +[2026-02-16T09:03:27.144Z] Ready! Logged in as AsepXiaoQin#6954 +Bot berhasil login! +[2026-02-16T09:03:27.145Z] FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +Ready! Logged in as AsepXiaoQin#6954 +FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +[2026-02-16T09:03:27.255Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * +[dotenv@17.3.1] injecting env (4) from .env -- tip: ⚙️ override existing env vars with { override: true } +[2026-02-16T09:04:34.158Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T09:04:34.816Z] Bot berhasil login! +Bot berhasil login! +[2026-02-16T09:04:34.818Z] Ready! Logged in as AsepXiaoQin#6954 +[2026-02-16T09:04:34.821Z] FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +Ready! Logged in as AsepXiaoQin#6954 +FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +[2026-02-16T09:04:34.895Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * +[dotenv@17.3.1] injecting env (4) from .env -- tip: 🛠️ run anywhere with `dotenvx run -- yourcommand` +[2026-02-16T09:04:57.611Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T09:04:58.667Z] Bot berhasil login! +Bot berhasil login! +[2026-02-16T09:04:58.668Z] Ready! Logged in as AsepXiaoQin#6954 +[2026-02-16T09:04:58.668Z] FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +Ready! Logged in as AsepXiaoQin#6954 +FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg +[2026-02-16T09:04:58.709Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * +[2026-02-16T09:08:16.758Z] Validation for "https://open.spotify.com/track/3qhlB30KknSejmIvZZLjOD?si=2NMmRTKnQJ-fMh9OmWm9Bw": sp_track +Validation for "https://open.spotify.com/track/3qhlB30KknSejmIvZZLjOD?si=2NMmRTKnQJ-fMh9OmWm9Bw": sp_track +[2026-02-16T09:08:16.760Z] Info fetch error: This is not a YouTube Watch URL +[2026-02-16T09:08:16.761Z] Playing: https://open.spotify.com/track/3qhlB30KknSejmIvZZLjOD?si=2NMmRTKnQJ-fMh9OmWm9Bw +Info fetch error: This is not a YouTube Watch URL +Playing: https://open.spotify.com/track/3qhlB30KknSejmIvZZLjOD?si=2NMmRTKnQJ-fMh9OmWm9Bw +[2026-02-16T09:08:16.772Z] Play Error: ffmpeg is not installed at 'ffmpeg' path +Play Error: ffmpeg is not installed at 'ffmpeg' path +[2026-02-16T09:08:29.785Z] Validation for "y que fue": search +[2026-02-16T09:08:29.786Z] Searching via play-dl for: y que fue +Validation for "y que fue": search +Searching via play-dl for: y que fue +[2026-02-16T09:08:30.242Z] Playing: https://www.youtube.com/watch?v=vHeO-9G5rxo +Playing: https://www.youtube.com/watch?v=vHeO-9G5rxo +[2026-02-16T09:08:30.247Z] Play Error: ffmpeg is not installed at 'ffmpeg' path +Play Error: ffmpeg is not installed at 'ffmpeg' path +[2026-02-16T09:08:35.195Z] Playing local file independently: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +Playing local file independently: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 diff --git a/bot/index.js b/bot/index.js index 9b304f6..b20f79e 100644 --- a/bot/index.js +++ b/bot/index.js @@ -1,6 +1,6 @@ +process.env.FFMPEG_PATH = require('ffmpeg-static'); const { Client, GatewayIntentBits, Events, EmbedBuilder, PermissionsBitField } = require('discord.js'); const { DisTube } = require('distube'); -const { YtDlpPlugin } = require('@distube/yt-dlp'); const { SoundCloudPlugin } = require('@distube/soundcloud'); const { SpotifyPlugin } = require('@distube/spotify'); const play = require('play-dl'); @@ -18,14 +18,6 @@ const fs = require('fs'); // Load environment variables require('dotenv').config({ path: path.join(__dirname, '.env') }); -// Setup FFMPEG -const ffmpegStatic = require('ffmpeg-static'); -process.env.FFMPEG_PATH = ffmpegStatic; -const ffmpegDir = path.dirname(ffmpegStatic); -if (!process.env.PATH.includes(ffmpegDir)) { - process.env.PATH = `${ffmpegDir}${path.delimiter}${process.env.PATH}`; -} - const client = new Client({ intents: [ GatewayIntentBits.Guilds, @@ -51,7 +43,6 @@ const distube = new DisTube(client, { plugins: [ new SoundCloudPlugin(), new SpotifyPlugin(), - new YtDlpPlugin(), ], emitAddSongWhenCreatingQueue: false, }); @@ -175,30 +166,53 @@ client.on(Events.InteractionCreate, async interaction => { } else if (commandName === 'play') { - const query = interaction.options.getString('query'); - if (!voiceChannel) return interaction.reply({ content: 'Anda harus berada di voice channel!', ephemeral: true }); - await interaction.deferReply(); - logToFile(`Searching via play-dl for: ${query}`); + const query = interaction.options.getString('query'); + const voiceChannel = interaction.member?.voice.channel; + + if (!voiceChannel) return interaction.editReply({ content: 'Anda harus berada di voice channel!' }); try { - const searchResults = await play.search(query, { limit: 1 }); - if (!searchResults || searchResults.length === 0) { - return interaction.editReply('Lagu tidak ditemukan!'); - } - const url = searchResults[0].url; - logToFile(`Found URL via play-dl: ${url}`); + let url = query; + let title = query; + const validation = await play.validate(query); + + logToFile(`Validation for "${query}": ${validation}`); - await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false }); + if (!validation || validation === 'search') { + logToFile(`Searching via play-dl for: ${query}`); + const searchResults = await play.search(query, { limit: 1 }); + + if (!searchResults || searchResults.length === 0) { + return interaction.editReply('Lagu tidak ditemukan!'); + } + + url = searchResults[0].url; + title = searchResults[0].title; + } else { + // It's a URL, attempt to get title + try { + const info = await play.video_info(url); + title = info.video_details.title; + url = info.video_details.url; + } catch (err) { + logToFile(`Info fetch error: ${err.message}`); + } + } + + logToFile(`Playing: ${url}`); await distube.play(voiceChannel, url, { member: interaction.member, textChannel: interaction.channel, - interaction + metadata: { interaction, songTitle: title } }); - await interaction.editReply(`Mencari: **${query}**... 🔍`); + + await interaction.editReply(`Memainkan: **${title}**... 🎶`); } catch (e) { logToFile(`Play Error: ${e.message}`); - interaction.editReply(`Terjadi kesalahan saat memutar: ${e.message}`); + if (interaction.deferred) { + await interaction.editReply(`Terjadi kesalahan: ${e.message}`); + } } } @@ -246,13 +260,27 @@ client.on(Events.MessageCreate, async message => { if (!query) return message.reply('Masukkan judul atau link lagu!'); try { - const searchResults = await play.search(query, { limit: 1 }); - if (!searchResults || searchResults.length === 0) { - return message.reply('Lagu tidak ditemukan!'); + let url = query; + let title = query; + const validation = await play.validate(query); + + if (!validation || validation === 'search') { + const searchResults = await play.search(query, { limit: 1 }); + if (!searchResults || searchResults.length === 0) return message.reply('Lagu tidak ditemukan!'); + url = searchResults[0].url; + title = searchResults[0].title; + } else { + try { + const info = await play.video_info(url); + title = info.video_details.title; + url = info.video_details.url; + } catch (err) { + logToFile(`Prefix info fetch error: ${err.message}`); + } } - const url = searchResults[0].url; - await distube.voices.join(voiceChannel, { selfDeaf: false, selfMute: false }); + message.reply(`🔍 Memainkan: **${title}**...`); + await distube.play(voiceChannel, url, { member: message.member, textChannel: message.channel,