Bugfix: Deleted Original Channel
This commit is contained in:
12
index.js
12
index.js
@@ -4,6 +4,9 @@ const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBit
|
||||
const token = process.env.BOT_TOKEN;
|
||||
const joinToCreateChannelId = process.env.JOINTOCREATE_CHANNEL_ID;
|
||||
|
||||
// Set to true if a channel was created by the bot
|
||||
const CREATED_BY_BOT = 'created_by_bot';
|
||||
|
||||
client.once('ready', () => {
|
||||
console.log('Ready!');
|
||||
});
|
||||
@@ -14,13 +17,18 @@ client.on('voiceStateUpdate', (oldState, newState) => {
|
||||
name: `🔊 ${newState.member.displayName}'s Channel`,
|
||||
type: ChannelType.GuildVoice,
|
||||
parent: newState.channel.parentId,
|
||||
reason: 'Created by JoinToCreate bot', // Add a reason when creating the channel
|
||||
}).then(channel => {
|
||||
newState.member.voice.setChannel(channel);
|
||||
channel[CREATED_BY_BOT] = true; // Mark the channel as created by the bot
|
||||
}).catch(console.error);
|
||||
}
|
||||
|
||||
if (oldState.channel && oldState.channel.members.size === 0 && oldState.channelId !== joinToCreateChannelId) {
|
||||
oldState.channel.delete().catch(console.error);
|
||||
if (oldState.channel && oldState.channel.members.size === 0 && oldState.channel.id !== joinToCreateChannelId) {
|
||||
// Check if the channel was created by the bot before deleting it
|
||||
if (oldState.channel[CREATED_BY_BOT]) {
|
||||
oldState.channel.delete().catch(console.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user