Skip to content

Commit

Permalink
fix: crash relating to leaving guild while session is active
Browse files Browse the repository at this point in the history
  • Loading branch information
zapteryx committed Oct 19, 2022
1 parent c4fce92 commit ab04bbc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/events/guildDelete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import type { WardenClient, WardenPlayer } from '#src/lib/util/common.d.js';
import { logger } from '#src/lib/util/common.js';
import type { Guild } from 'discord.js';

export default {
name: 'guildDelete',
once: false,
execute(guild: Guild): void {
async execute(guild: Guild & { client: WardenClient }): Promise<void> {
logger.info({
message: `[G ${guild.id}] Left guild ${guild.name}`,
label: 'Discord',
});
const player = guild.client.tts.players.get(guild.id) as WardenPlayer;
if (player) {
logger.info({
message: `[G ${guild.id}] Cleaning up`,
label: 'Warden',
});
player.channelId = null;
return player.handler.disconnect();
}
},
};

0 comments on commit ab04bbc

Please sign in to comment.