// code to play songs /* eslint-disable array-element-newline, no-magic-numbers */ import { StreamType, AudioPlayerStatus, createAudioResource, entersState, } from '@discordjs/voice'; import prism from 'prism-media'; const PLAYING_TIME = 5_000; const FFMPEG_ARGUMENTS = [ '-analyzeduration', '0', '-loglevel', '0', '-f', 's16le', '-ar', '48000', '-ac', '2', ]; export default function playSong (stream, player, sec = 0, min = 0) { const hr = Math.floor(min / 60) .toString() .padStart(2, '0'); min = (min % 60) .toString() .padStart(2, '0'); sec = sec .toString() .padStart(2, '0'); const transcoder = new prism.FFmpeg({ args: [ '-ss', `${hr}:${min}:${sec}`, ...FFMPEG_ARGUMENTS ], }); const resource = createAudioResource(stream.pipe(transcoder), { inputType: StreamType.Raw, }); player.play(resource); return entersState(player, AudioPlayerStatus.Playing, PLAYING_TIME); } // commnad to play songs import { createAudioPlayer } from '@discordjs/voice'; import ytdl from 'ytdl-core'; import { search } from '../youtube.js'; import playSong from '../playSong.js'; export default { async command (interaction, connection) { const player = createAudioPlayer(); const [ result ] = (await search( interaction.options.get('query').value, 1, )).items; await interaction.reply(`Now playing \`${result.snippet.title}\``); await connection.subscribe(player); const stream = ytdl(`https://www.youtube.com/watch?v=${result.id.videoId}`); await playSong(stream, player); Object.assign(player, { startTime: Date.now() }); return { player, stream }; }, }; // command to seek, which is where it is failing import playSong from '../playSong.js'; export default { async command (interaction, connection, player, stream) { const position = interaction.options.get('position').value; await player.stop(); await playSong(stream, player, ...position.split(':').reverse()); interaction.reply(`Seeked \`${position}\``); }, };