diff --git a/src/events/client/ChannelDelete.ts b/src/events/client/ChannelDelete.ts new file mode 100644 index 000000000..1fc1ceeaf --- /dev/null +++ b/src/events/client/ChannelDelete.ts @@ -0,0 +1,42 @@ +import { Event, type Lavamusic } from "../../structures/index.js"; + +export default class ChannelDelete extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: "channelDelete", + }); + } + + public async run(channel: any): Promise { + const { guild } = channel; + const setup = await this.client.db.getSetup(guild.id); + const stay = await this.client.db.get_247(guild.id); + + if (Array.isArray(stay)) { + for (const s of stay) { + if (channel.type === 2 && s.voiceId === channel.id) { + await this.client.db.delete_247(guild.id); + break; + } + } + } else if (stay) { + if (channel.type === 2 && stay.voiceId === channel.id) { + await this.client.db.delete_247(guild.id); + } + } + + if (setup && channel.type === 0 && setup.textId === channel.id) { + await this.client.db.deleteSetup(guild.id); + } + + const queue = this.client.queue.get(guild.id); + if (queue) { + if ( + queue.channelId === channel.id || + (queue.player && queue.node.manager.connections.get(guild.id)!.channelId === channel.id) + ) { + queue.stop(); + } + } + } +} diff --git a/src/events/player/NodeConnect.ts b/src/events/player/NodeConnect.ts index 223262637..4a186ce96 100644 --- a/src/events/player/NodeConnect.ts +++ b/src/events/player/NodeConnect.ts @@ -27,7 +27,15 @@ export default class NodeConnect extends Event { const vc = guild.channels.cache.get(main.voiceId); if (channel && vc) { - await this.client.queue.create(guild, vc, channel); + try { + await this.client.queue.create(guild, vc, channel); + } catch (error) { + this.client.logger.error(`Failed to create queue for guild ${guild.id}: ${error.message}`); + } + } else { + this.client.logger.warn( + `Missing channels for guild ${guild.id}. Text channel: ${main.textId}, Voice channel: ${main.voiceId}`, + ); } }, index * 1000); }); @@ -35,14 +43,3 @@ export default class NodeConnect extends Event { BotLog.send(this.client, `Node ${node} is ready!`, "success"); } } - -/** - * Project: lavamusic - * Author: Appu - * Main Contributor: LucasB25 - * Company: Coders - * Copyright (c) 2024. All rights reserved. - * This code is the property of Coder and may not be reproduced or - * modified without permission. For more information, contact us at - * https://discord.gg/ns8CTk9J3e - */