Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commands/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
} catch (err) {
console.error(err)
res.setDescription('播放時發生錯誤,可能是因為網址錯誤或是無法播放此網址的音樂\n如果要搜尋,請使用 `/search` 指令')
return interaction.followUp({ embeds: [res] })
return interaction.editReply({ embeds: [res] })
}

}
Expand Down
2 changes: 0 additions & 2 deletions commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ module.exports = {
const start = interaction.options.getInteger('起始歌曲編號') ?? 1
const end = Math.min(interaction.options.getInteger('結尾歌曲編號') ?? start, dj.queue.length)

console.log(start, end)

if (start > end) {
res.setDescription('結尾怎麼會小於開頭呢?這樣怎麼對?')
return interaction.reply({ embeds: [res], flags: MessageFlags.Ephemeral })
Expand Down
5 changes: 5 additions & 0 deletions commands/resend.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module.exports = {
return interaction.reply({ embeds: [res], flags: MessageFlags.Ephemeral })
}

if (!dj.nowPlaying) {
res.setDescription('目前沒有正在播放的歌曲,遙控器沒東西可以遙控')
return interaction.reply({ embeds: [res], flags: MessageFlags.Ephemeral })
}

await interaction.deferReply({ flags: MessageFlags.Ephemeral })

try {
Expand Down
5 changes: 2 additions & 3 deletions commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ module.exports = {
}

const index = i.values[0]
message.delete()
return results[index]
}).catch(() => {
message.delete()
Expand All @@ -127,11 +126,11 @@ module.exports = {
if (!result) return

try {
dj.playWithAdapter(interaction, result.url, adapter)
await dj.playWithAdapter(interaction, result.url, adapter)
} catch (e) {
console.error(e)
res.setDescription('無法播放此歌曲')
return interaction.followUp({ embeds: [res] })
return interaction.editReply({ embeds: [res], components: [] })
}

}
Expand Down
16 changes: 8 additions & 8 deletions music/GuildMusicManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GuildMusicManager {
if (!this.canAutoUnsuppress(interaction)) return

if (this.queue.length >= this.maxQueueSize) {
interaction.followUp(`隊列已超過上限 ${this.maxQueueSize} 首,請等待目前的歌曲播放完畢,或是移除一些歌曲後再試`).then(msg => {
interaction.editReply({ content: `隊列已超過上限 ${this.maxQueueSize} 首,請等待目前的歌曲播放完畢,或是移除一些歌曲後再試`, components: [], embeds: [] }).then(msg => {
setTimeout(() => msg.delete(), 5000)
})
return
Expand All @@ -71,10 +71,10 @@ class GuildMusicManager {
const track = new Track(this.client, inputURL, metadata, interaction.member, adapter)
this.queue.push(track)

await interaction.followUp({ embeds: [track.getQueuedEmbed()] })
await interaction.editReply({ embeds: [track.getQueuedEmbed()], components: [] })
} catch (e) {
console.error(e)
return interaction.followUp('目前無法正確播放這首歌曲')
return interaction.editReply({ content: '目前無法正確播放這首歌曲', components: [], embeds: [] })
}

if (!this.isPlaying) {
Expand All @@ -87,7 +87,7 @@ class GuildMusicManager {
}

async playlistWithAdapter(interaction, query, adapter) {
const message = await interaction.followUp('解析播放清單中,若播放清單過長,可能會花上幾分鐘,請耐心等候......')
const message = await interaction.editReply({ content: '解析播放清單中,若播放清單過長,可能會花上幾分鐘,請耐心等候......', components: [], embeds: [] })

try {
const data = await adapter.getBulkTrackInfo(query)
Expand All @@ -98,10 +98,10 @@ class GuildMusicManager {

if (!data.length) {
res.setDescription('很遺憾,這個播放清單中沒有我可以播放的樂曲')
return message.edit({ content: '', embeds: [res] }).catch(console.error)
return message.edit({ content: '', embeds: [res], components: [] }).catch(console.error)
}

await message.edit('播放清單解析完成,正在加入隊列中......').catch(console.error)
await message.edit({ content: '播放清單解析完成,正在加入隊列中......', components: [], embeds: [] }).catch(console.error)

const tracks = data.map(({ inputURL, metadata }) => new Track(this.client, inputURL, metadata, interaction.member, adapter))
const thumbnail = data.find(track => track.metadata.thumbnail)?.metadata?.thumbnail
Expand All @@ -112,10 +112,10 @@ class GuildMusicManager {

if (thumbnail) res.setThumbnail(thumbnail)

await message.edit({ content: '', embeds: [res] }).catch(console.error)
await message.edit({ content: '', embeds: [res], components: [] }).catch(console.error)
} catch (e) {
console.error(e)
return message.edit('出現未知錯誤,已停止').catch(console.error)
return message.edit({ content: '出現未知錯誤,已停止', components: [], embeds: [] }).catch(console.error)
}

if (!this.isPlaying) {
Expand Down
2 changes: 1 addition & 1 deletion music/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Track {
this.startMs = startTimeMs

const mediaURL = await this.adapter.getResourceURL(this.inputURL)
const FFMPEG_OPUS_ARGUMENTS = ['-i', mediaURL, '-ss', ~~(this.starTimeMs)/1000, '-analyzeduration', '0', '-loglevel', '0', '-acodec', 'libopus', '-f', 'opus', '-ar', '48000', '-ac', '2']
const FFMPEG_OPUS_ARGUMENTS = ['-i', mediaURL, '-ss', ~~(this.startMs)/1000, '-analyzeduration', '0', '-loglevel', '0', '-acodec', 'libopus', '-f', 'opus', '-ar', '48000', '-ac', '2']
const RECONNECT_ARGUMENTS = ['-reconnect', '1', '-reconnect_streamed', '1', '-reconnect_delay_max', '5']
const stream = new prism.FFmpeg({
args: [...RECONNECT_ARGUMENTS, ...FFMPEG_OPUS_ARGUMENTS]
Expand Down
10 changes: 6 additions & 4 deletions music/adapters/YoutubeAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const YoutubeAdapter = {

async getBulkTrackInfo(url) {
const stdout = await execute('yt-dlp', [
'-i', '-x', '--dump-json', '--skip-download', '--geo-bypass', '--', url
'--js-runtimes', 'node', '-i', '-x', '--dump-json', '--skip-download', '--geo-bypass', '--', url
])

return stdout.split('\n')
Expand All @@ -57,6 +57,7 @@ const YoutubeAdapter = {
_search(query, limit) {
if (isNaN(+limit)) throw Error('limit must be a number')
return execute('yt-dlp', [
'--js-runtimes', 'node',
`ytsearch${limit}:${query}`,
'--dump-json',
'--flat-playlist',
Expand All @@ -65,11 +66,12 @@ const YoutubeAdapter = {
return stdout.split('\n')
.filter(line => line.trim())
.map(line => JSON.parse(line))
.filter(result => result.ie_key === 'Youtube')
})
},

getResourceURL(url) {
return execute('yt-dlp', ['-i', '-x', '--get-url', '--geo-bypass', '--', url])
return execute('yt-dlp', ['--js-runtimes', 'node', '-i', '-x', '--get-url', '--geo-bypass', '--', url])
.then(stdout => stdout.trim())
},

Expand All @@ -94,13 +96,13 @@ const YoutubeAdapter = {

_getDumpData(url) {
return execute('yt-dlp', [
'-i', '-x', '--dump-json', '--flat-playlist', '--skip-download', '--geo-bypass', '--', url
'--js-runtimes', 'node', '-i', '-x', '--dump-json', '--flat-playlist', '--skip-download', '--geo-bypass', '--', url
]).then(stdout => JSON.parse(stdout))
},

_resolvePlaylistToURL(url) {
return execute('yt-dlp', [
'-i', '-x', '--get-url', '--flat-playlist', '--skip-download', '--geo-bypass', '--', url
'--js-runtimes', 'node', '-i', '-x', '--get-url', '--flat-playlist', '--skip-download', '--geo-bypass', '--', url
]).then(stdout => stdout.split('\n').filter(line => line.trim()))
}
};
Expand Down