Skip to content

Commit

Permalink
fix:crash in music command with huge playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzy2319 committed Oct 19, 2023
1 parent c50e11c commit 7fd7c0a
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/Commands/Music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const command: AppSlashCommandBuilder = (new AppSlashCommandBuilder())
.setRequired(true)
)
.setCallback(async (client: Client, interaction: CommandInteraction) => {
let rep: boolean = false
const voiceChan: VoiceBasedChannel | null = (await interaction.guild.members.fetch(interaction.user.id))
?.voice
.channel
Expand All @@ -51,19 +50,19 @@ const command: AppSlashCommandBuilder = (new AppSlashCommandBuilder())
.value as string
const queue: YoutubeVideoInfo[] = QueueProvider.GetGuildQueue(interaction.guild)

await interaction.deferReply({ ephemeral: true })

if (voiceChan === null) {
await interaction.reply({
content: translator.getTranslation('command.music.action.error.not_connected', interaction.guild.preferredLocale),
ephemeral: true
await interaction.followUp({
content: translator.getTranslation('command.music.action.error.not_connected', interaction.guild.preferredLocale)
})

return
}

if (!url.startsWith('https') || !play.yt_validate(url)) {
await interaction.reply({
content: translator.getTranslation('command.music.action.error.link_not_valid', interaction.guild.preferredLocale),
ephemeral: true
await interaction.followUp({
content: translator.getTranslation('command.music.action.error.link_not_valid', interaction.guild.preferredLocale)
})

return
Expand All @@ -79,10 +78,8 @@ const command: AppSlashCommandBuilder = (new AppSlashCommandBuilder())
}

if (queue.length > 0) {
rep = true
await interaction.reply({
content: translator.getTranslation('command.music.action.added_to_queue', interaction.guild.preferredLocale),
ephemeral: true
await interaction.followUp({
content: translator.getTranslation('command.music.action.added_to_queue', interaction.guild.preferredLocale)
})
}

Expand All @@ -91,17 +88,13 @@ const command: AppSlashCommandBuilder = (new AppSlashCommandBuilder())
}

if (QueueProvider.GetGuildQueue(interaction.guild).length === 0) {
await interaction.reply({
content: translator.getTranslation('command.music.action.error.private', interaction.guild.preferredLocale),
ephemeral: true
await interaction.followUp({
content: translator.getTranslation('command.music.action.error.private', interaction.guild.preferredLocale)
})

return
}

if (!rep) {
await interaction.deferReply()
}
const connection: VoiceConnection = joinVoiceChannel({
channelId: voiceChan.id,
guildId: voiceChan.guild.id,
Expand Down Expand Up @@ -178,11 +171,12 @@ const command: AppSlashCommandBuilder = (new AppSlashCommandBuilder())

await playMusic()

let message: Message = await interaction.followUp(
interaction.deleteReply()

let message: Message = await interaction.channel.send(
{
embeds: [getEmbed()],
components: [getActions()],
fetchReply: true
components: [getActions()]
}
)

Expand Down

0 comments on commit 7fd7c0a

Please sign in to comment.