diff --git a/bot/bot.log b/bot/bot.log index 5761667..1b3e17b 100644 --- a/bot/bot.log +++ b/bot/bot.log @@ -1397,3 +1397,111 @@ Ready! Logged in as AsepXiaoQin#6954 FFMPEG Path: /home/ubuntu/executor/workspace/bot/node_modules/ffmpeg-static/ffmpeg [2026-02-16T07:37:26.937Z] Alarm scheduled at 30 3 * * * Alarm scheduled at 30 3 * * * +[2026-02-16T07:40:13.926Z] Playing local file using stream: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +Playing local file using stream: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +TypeError: Cannot read properties of undefined (reading 'ended') + at AudioPlayer.play (/home/ubuntu/executor/workspace/bot/node_modules/@discordjs/voice/dist/index.js:466:18) + at DisTubeVoice.play (/home/ubuntu/executor/workspace/bot/node_modules/distube/dist/index.js:434:24) + at process.processTicksAndRejections (node:internal/process/task_queues:105:5) +[2026-02-16T07:40:13.938Z] Unhandled Rejection: Cannot read properties of undefined (reading 'ended') +Unhandled Rejection: Cannot read properties of undefined (reading 'ended') +TypeError: Cannot read properties of undefined (reading 'ended') + at AudioPlayer.play (/home/ubuntu/executor/workspace/bot/node_modules/@discordjs/voice/dist/index.js:466:18) + at DisTubeVoice.play (/home/ubuntu/executor/workspace/bot/node_modules/distube/dist/index.js:434:24) + at process.processTicksAndRejections (node:internal/process/task_queues:105:5) +[2026-02-16T07:40:30.187Z] Fetching stream for: https://on.soundcloud.com/gkAiIpJUfj0jHErChg +Fetching stream for: https://on.soundcloud.com/gkAiIpJUfj0jHErChg +[2026-02-16T07:40:34.820Z] 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 Socket. (node:internal/child_process:456:11) + at Socket.emit (node:events:518:28) + at Pipe. (node:net:346:12) +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 Socket. (node:internal/child_process:456:11) + at Socket.emit (node:events:518:28) + at Pipe. (node:net:346:12) +[2026-02-16T07:41:03.881Z] Fetching stream for: y que fue +Fetching stream for: y que fue +[2026-02-16T07:41:19.211Z] Playing local file using stream: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +Playing local file using stream: /home/ubuntu/executor/workspace/bot/assets/audio/sahur.mp3 +TypeError: Cannot read properties of undefined (reading 'ended') + at AudioPlayer.play (/home/ubuntu/executor/workspace/bot/node_modules/@discordjs/voice/dist/index.js:466:18) + at DisTubeVoice.play (/home/ubuntu/executor/workspace/bot/node_modules/distube/dist/index.js:434:24) + at process.processTicksAndRejections (node:internal/process/task_queues:105:5) +[2026-02-16T07:41:19.216Z] Unhandled Rejection: Cannot read properties of undefined (reading 'ended') +Unhandled Rejection: Cannot read properties of undefined (reading 'ended') +TypeError: Cannot read properties of undefined (reading 'ended') + at AudioPlayer.play (/home/ubuntu/executor/workspace/bot/node_modules/@discordjs/voice/dist/index.js:466:18) + at DisTubeVoice.play (/home/ubuntu/executor/workspace/bot/node_modules/distube/dist/index.js:434:24) + at process.processTicksAndRejections (node:internal/process/task_queues:105:5) +[dotenv@17.3.1] injecting env (4) from .env -- tip: ⚙️ enable debug logging with { debug: true } +Dependency Report: +-------------------------------------------------- +Core Dependencies +- @discordjs/voice: 0.19.0 +- prism-media: 1.3.5 + +Opus Libraries +- @discordjs/opus: 0.9.0 +- opusscript: 0.0.8 + +Encryption Libraries +- native crypto support for aes-256-gcm: yes +- sodium-native: 5.0.10 +- sodium: not found +- libsodium-wrappers: 0.7.16 +- @stablelib/xchacha20poly1305: 2.0.1 +- @noble/ciphers: not found + +DAVE Libraries +- @snazzah/davey: 0.1.9 + +FFmpeg +- version: 7.0.2-static https://johnvansickle.com/ffmpeg/ +- libopus: yes +-------------------------------------------------- +[dotenv@17.3.1] injecting env (4) from .env -- tip: 🛠️ run anywhere with `dotenvx run -- yourcommand` +Dependency Report: +-------------------------------------------------- +Core Dependencies +- @discordjs/voice: 0.19.0 +- prism-media: 1.3.5 + +Opus Libraries +- @discordjs/opus: 0.9.0 +- opusscript: 0.0.8 + +Encryption Libraries +- native crypto support for aes-256-gcm: yes +- sodium-native: 5.0.10 +- sodium: not found +- libsodium-wrappers: 0.7.16 +- @stablelib/xchacha20poly1305: 2.0.1 +- @noble/ciphers: not found + +DAVE Libraries +- @snazzah/davey: 0.1.9 + +FFmpeg +- version: 7.0.2-static https://johnvansickle.com/ffmpeg/ +- libopus: yes +-------------------------------------------------- +[2026-02-16T07:44:22.778Z] Encryption library (libsodium) is ready. +Encryption library (libsodium) is ready. +[2026-02-16T07:44:25.785Z] Bot berhasil login! +[2026-02-16T07:44:25.785Z] Ready! Logged in as AsepXiaoQin#6954 +[2026-02-16T07:44:25.786Z] 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-16T07:44:26.800Z] Alarm scheduled at 30 3 * * * +Alarm scheduled at 30 3 * * * diff --git a/bot/index.js b/bot/index.js index 57c2647..e0858aa 100644 --- a/bot/index.js +++ b/bot/index.js @@ -1,4 +1,12 @@ const { Client, GatewayIntentBits, Events, EmbedBuilder, PermissionsBitField } = require('discord.js'); +const { + joinVoiceChannel, + createAudioPlayer, + createAudioResource, + AudioPlayerStatus, + StreamType, + VoiceConnectionStatus +} = require('@discordjs/voice'); const { DisTube } = require('distube'); const { YtDlpPlugin } = require('@distube/yt-dlp'); const { SoundCloudPlugin } = require('@distube/soundcloud'); @@ -67,6 +75,37 @@ function logToFile(message) { console.log(message); } +async function playLocalFile(voiceChannel) { + const connection = joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: voiceChannel.guild.id, + adapterCreator: voiceChannel.guild.voiceAdapterCreator, + selfDeaf: false, + selfMute: false, + }); + + const player = createAudioPlayer(); + + player.on('error', error => { + logToFile(`Audio Player Error: ${error.message}`); + }); + + const resource = createAudioResource(AUDIO_PATH, { + inputType: StreamType.Arbitrary, + inlineVolume: true, + }); + + resource.volume.setVolume(1.0); + player.play(resource); + connection.subscribe(player); + + player.on(AudioPlayerStatus.Idle, () => { + // connection.destroy(); + }); + + return connection; +} + client.once(Events.ClientReady, () => { logToFile(`Bot berhasil login!`); logToFile(`Ready! Logged in as ${client.user.tag}`); @@ -90,12 +129,29 @@ client.once(Events.ClientReady, () => { if (!guild) return; const channel = guild.channels.cache.get(VC_ID); if (channel && fs.existsSync(AUDIO_PATH)) { - distube.voices.join(channel).then(voice => { - const stream = fs.createReadStream(AUDIO_PATH); - voice.play(stream); - }).catch(err => { + try { + const connection = joinVoiceChannel({ + channelId: channel.id, + guildId: guild.id, + adapterCreator: guild.voiceAdapterCreator, + selfDeaf: false, + selfMute: false, + }); + + const player = createAudioPlayer(); + const resource = createAudioResource(AUDIO_PATH, { + inputType: StreamType.Arbitrary, + inlineVolume: true, + }); + + resource.volume.setVolume(1.0); + player.play(resource); + connection.subscribe(player); + + logToFile('Alarm playing with custom audio resource.'); + } catch (err) { logToFile(`Alarm join error: ${err.message}`); - }); + } } }, null, true, 'Asia/Jakarta'); logToFile(`Alarm scheduled at ${cronTime}`); @@ -115,7 +171,13 @@ client.on(Events.InteractionCreate, async interaction => { if (commandName === 'join') { if (!voiceChannel) return interaction.reply({ content: 'Anda harus berada di voice channel!', ephemeral: true }); await interaction.deferReply(); - await distube.voices.join(voiceChannel); + joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: voiceChannel.guild.id, + adapterCreator: voiceChannel.guild.voiceAdapterCreator, + selfDeaf: false, + selfMute: false, + }); await interaction.editReply('Sudah join! 🎧'); } @@ -124,11 +186,9 @@ client.on(Events.InteractionCreate, async interaction => { if (!fs.existsSync(AUDIO_PATH)) return interaction.reply({ content: `File audio tidak ditemukan di ${AUDIO_PATH}`, ephemeral: true }); await interaction.deferReply(); - logToFile(`Playing local file using stream: ${AUDIO_PATH}`); + logToFile(`Playing local file using custom resource: ${AUDIO_PATH}`); try { - const voice = await distube.voices.join(voiceChannel); - const stream = fs.createReadStream(AUDIO_PATH); - voice.play(stream); + await playLocalFile(voiceChannel); await interaction.editReply('Memainkan suara sahur... 📢'); } catch (e) { logToFile(`Error in testsahur: ${e.message}`); @@ -142,6 +202,16 @@ client.on(Events.InteractionCreate, async interaction => { await interaction.deferReply(); logToFile(`Fetching stream for: ${query}`); + + // Ensure connection with specific settings + joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: voiceChannel.guild.id, + adapterCreator: voiceChannel.guild.voiceAdapterCreator, + selfDeaf: false, + selfMute: false, + }); + distube.play(voiceChannel, query, { member: interaction.member, textChannel: interaction.channel, @@ -195,6 +265,15 @@ client.on(Events.MessageCreate, async message => { const query = args.join(' '); if (!voiceChannel) return message.reply('Anda harus berada di voice channel!'); if (!query) return message.reply('Masukkan judul atau link lagu!'); + + joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: voiceChannel.guild.id, + adapterCreator: voiceChannel.guild.voiceAdapterCreator, + selfDeaf: false, + selfMute: false, + }); + distube.play(voiceChannel, query, { member: message.member, textChannel: message.channel, @@ -208,9 +287,7 @@ client.on(Events.MessageCreate, async message => { } else if (command === 'testsahur') { if (!voiceChannel) return message.reply('Anda harus berada di voice channel!'); try { - const voice = await distube.voices.join(voiceChannel); - const stream = fs.createReadStream(AUDIO_PATH); - voice.play(stream); + await playLocalFile(voiceChannel); message.reply('Mengetes suara sahur... 📢'); } catch (e) { message.reply(`❌ Error: ${e.message}`);