@@ -78,7 +78,9 @@ export class ChannelsService extends GuildService {
78
78
private async getCategoryChannels ( ) : Promise < VoiceChannel [ ] > {
79
79
const guild = await this . getGuild ( ) ;
80
80
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 [ ] ;
82
84
}
83
85
84
86
private async getMaxBitrate ( ) : Promise < number > {
@@ -160,7 +162,7 @@ export class ChannelsService extends GuildService {
160
162
type : ChannelType . GuildVoice ,
161
163
parent : this . getVoiceCategoryId ( ) ,
162
164
position : index ,
163
- // topic: `dynamically created voice channel number ${index + 1} `,
165
+ // topic: `i love apples `,
164
166
bitrate : await this . getMaxBitrate ( )
165
167
} ) ;
166
168
@@ -178,8 +180,8 @@ export class ChannelsService extends GuildService {
178
180
private async updateChannel ( channel : VoiceBasedChannel , index : number ) : Promise < void > {
179
181
try {
180
182
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 `
183
185
} ) ;
184
186
185
187
this . logger . log ( `Renamed channel ${ channel . name } to ${ updatedChannel . name } ` ) ;
@@ -195,13 +197,26 @@ export class ChannelsService extends GuildService {
195
197
196
198
private async deleteChannel ( channel : VoiceBasedChannel ) : Promise < void > {
197
199
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
+ }
199
206
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 ( ) ;
200
213
this . logger . log ( `Deleted channel ${ channel . name } ` ) ;
201
214
} catch ( e ) {
202
215
const error = e as DiscordAPIError ;
203
216
if ( error . code === 10003 ) {
204
217
this . logger . log ( 'Channel not found' ) ;
218
+ } else if ( error . code === 50013 ) {
219
+ this . logger . error ( `Missing permissions to delete channel ${ channel . name } ` ) ;
205
220
} else {
206
221
throw error ;
207
222
}
0 commit comments