Skip to content

Commit

Permalink
3.5.2
Browse files Browse the repository at this point in the history
When audioplayer throws PlayingError and the queue is empty, player destroys themselves.
Improved error output in Discord.
  • Loading branch information
AlexInCube committed Aug 6, 2024
1 parent a8a0673 commit d604d74
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aicbot",
"version": "3.5.1",
"version": "3.5.2",
"description": "Discord Bot for playing music",
"main": "build/main.js",
"scripts": {
Expand Down
18 changes: 10 additions & 8 deletions src/audioplayer/AudioPlayersManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ export class AudioPlayersManager {
const queue = this.distube.getQueue(voiceChannel.guildId);

if (!queue) return;
if (queue.songs.length === 0) await this.stop(voiceChannel.guild);
if (queue.songs.length === 0) await this.stop(voiceChannel.guild.id);
}
}

async stop(guild: Guild) {
const queue = this.distube.getQueue(guild);
async stop(guildId: string) {
const queue = this.distube.getQueue(guildId);

if (queue) {
await queue.stop();
queue.voice.leave();
} else {
this.distube.voices.leave(guild);
this.distube.voices.leave(guildId);
}

await this.playersManager.remove(guild.id);
await this.playersManager.remove(guildId);
}

async pause(guild: Guild) {
Expand Down Expand Up @@ -404,14 +404,16 @@ export class AudioPlayersManager {
if (queue._next || queue._prev || queue.stopped || queue.songs.length > 1) return;
await this.playersManager.get(queue.id)?.setState('waiting');
})
.on(DistubeEvents.ERROR, async (error, queue) => {
.on(DistubeEvents.ERROR, async (error, queue, song) => {
let errorName = `ERROR`;
const errorMessage = `${error.name} + \n\n + ${error.message}`;

if (queue.songs.length >= 1) {
errorName = queue.songs[0].name!;
if (song) {
errorName = song.name!;
}

if (queue.songs.length === 0) await this.stop(queue.id)

Check failure on line 415 in src/audioplayer/AudioPlayersManager.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Insert `;`

await queue.textChannel?.send({
embeds: [generateErrorEmbed(errorMessage, errorName)]
});
Expand Down
2 changes: 1 addition & 1 deletion src/audioplayer/PlayerButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class PlayerButtons {
});
}

await this.client.audioPlayer.stop(guild);
await this.client.audioPlayer.stop(guild.id);

await ButtonInteraction.deferUpdate();
break;
Expand Down
4 changes: 2 additions & 2 deletions src/audioplayer/PlayerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class PlayerInstance {
async startAfkTimer() {
try {
this.afkTimer = setTimeout(async () => {
await this.client.audioPlayer.stop(this.textChannel.guild);
await this.client.audioPlayer.stop(this.textChannel.guild.id);
await this.textChannel.send({
embeds: [generateSimpleEmbed(i18next.t('audioplayer:event_empty') as string)]
});
Expand Down Expand Up @@ -79,7 +79,7 @@ export class PlayerInstance {
// loggerSend('try to stop player on cooldown')
if (queue) return;
if (checkBotInVoice(this.textChannel.guild)) {
await this.client.audioPlayer.stop(this.textChannel.guild);
await this.client.audioPlayer.stop(this.textChannel.guild.id);
await this.textChannel.send({
embeds: [generateSimpleEmbed(i18next.t('audioplayer:event_finish_time') as string)]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Client, TextChannel } from 'discord.js';
export async function AudioPlayerEventChannelDelete(client: Client, channel: TextChannel) {
const player = client.audioPlayer.playersManager.get(channel.guild.id);
if (player?.textChannel.id === channel.id) {
await client.audioPlayer.stop(channel.guild);
await client.audioPlayer.stop(channel.guild.id);
}
}
10 changes: 9 additions & 1 deletion src/audioplayer/util/downloadSong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,13 @@ export function DownloadSongErrorGetLocale(errorMessage: DownloadSongMessage) {
maxDownloadSize: maxDownloadSizeMB
});
}
return i18next.t(`commands:download_song_error_${errorMessage}`);

const localeToken = `commands:download_song_error_${errorMessage}`

Check failure on line 113 in src/audioplayer/util/downloadSong.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Insert `;`
const locale = i18next.t(localeToken)

Check failure on line 114 in src/audioplayer/util/downloadSong.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Replace `··i18next.t(localeToken)` with `·i18next.t(localeToken);`

if (localeToken !== locale){

Check failure on line 116 in src/audioplayer/util/downloadSong.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Insert `·`
return locale

Check failure on line 117 in src/audioplayer/util/downloadSong.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Insert `;`
}

return errorMessage

Check failure on line 120 in src/audioplayer/util/downloadSong.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Insert `;`
}
6 changes: 3 additions & 3 deletions src/commands/audio/stop.command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICommand } from '../../CommandTypes.js';
import {
EmbedBuilder,
EmbedBuilder, Guild,

Check failure on line 3 in src/commands/audio/stop.command.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Insert `⏎·`
GuildMember,
Message,
PermissionsBitField,
Expand All @@ -21,7 +21,7 @@ export default function (): ICommand {
description: i18next.t('commands:stop_desc'),
execute: async (message: Message) => {
await AudioCommandWrapperText(message, async () => {
await message.client.audioPlayer.stop(message.guild!);
await message.client.audioPlayer.stop((message.guild as Guild).id);
await message.reply({ embeds: [generateEmbedAudioPlayerStop(message.member!)] });
});
}
Expand All @@ -32,7 +32,7 @@ export default function (): ICommand {
.setDescription(i18next.t('commands:stop_desc')),
execute: async (interaction) => {
await AudioCommandWrapperInteraction(interaction, async () => {
await interaction.client.audioPlayer.stop(interaction.guild!);
await interaction.client.audioPlayer.stop((interaction.guild as Guild).id);
await interaction.reply({
embeds: [generateEmbedAudioPlayerStop(interaction.member as GuildMember)]
});
Expand Down

0 comments on commit d604d74

Please sign in to comment.