@@ -78,7 +78,9 @@ export class ChannelsService extends GuildService {
7878 private async getCategoryChannels ( ) : Promise < VoiceChannel [ ] > {
7979 const guild = await this . getGuild ( ) ;
8080 const allChannels = Array . from ( guild . channels . cache . values ( ) ) ;
81- return allChannels . filter ( channel => channel . parentId === this . getVoiceCategoryId ( ) ) as VoiceChannel [ ] ;
81+ return allChannels . filter (
82+ channel => channel . parentId === this . getVoiceCategoryId ( ) && channel . type === ChannelType . GuildVoice
83+ ) as VoiceChannel [ ] ;
8284 }
8385
8486 private async getMaxBitrate ( ) : Promise < number > {
@@ -160,7 +162,7 @@ export class ChannelsService extends GuildService {
160162 type : ChannelType . GuildVoice ,
161163 parent : this . getVoiceCategoryId ( ) ,
162164 position : index ,
163- // topic: `dynamically created voice channel number ${index + 1} `,
165+ // topic: `i love apples `,
164166 bitrate : await this . getMaxBitrate ( )
165167 } ) ;
166168
@@ -178,8 +180,8 @@ export class ChannelsService extends GuildService {
178180 private async updateChannel ( channel : VoiceBasedChannel , index : number ) : Promise < void > {
179181 try {
180182 const updatedChannel = await channel . edit ( {
181- name : `voice ${ index + 1 } ` ,
182- topic : `dynamically created voice channel number ${ index + 1 } `
183+ name : `voice ${ index + 1 } `
184+ // topic: `i love apples `
183185 } ) ;
184186
185187 this . logger . log ( `Renamed channel ${ channel . name } to ${ updatedChannel . name } ` ) ;
@@ -195,13 +197,26 @@ export class ChannelsService extends GuildService {
195197
196198 private async deleteChannel ( channel : VoiceBasedChannel ) : Promise < void > {
197199 try {
198- await channel . delete ( ) ;
200+ const botMember = channel . guild . members . me ;
201+
202+ if ( ! botMember . permissions . has ( 'ManageChannels' ) ) {
203+ this . logger . error ( 'Bot lacks ManageChannels permission at server level' ) ;
204+ return ;
205+ }
199206
207+ if ( ! channel . permissionsFor ( botMember ) . has ( 'ManageChannels' ) ) {
208+ this . logger . error ( `Bot lacks ManageChannels permission for channel ${ channel . name } ` ) ;
209+ return ;
210+ }
211+
212+ await channel . delete ( ) ;
200213 this . logger . log ( `Deleted channel ${ channel . name } ` ) ;
201214 } catch ( e ) {
202215 const error = e as DiscordAPIError ;
203216 if ( error . code === 10003 ) {
204217 this . logger . log ( 'Channel not found' ) ;
218+ } else if ( error . code === 50013 ) {
219+ this . logger . error ( `Missing permissions to delete channel ${ channel . name } ` ) ;
205220 } else {
206221 throw error ;
207222 }
0 commit comments