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