@@ -165,11 +165,14 @@ async function showRolesStep(interaction: any, session: any) {
165165 const embed = createRolesEmbed ( session ) ;
166166 const guild = interaction . guild ;
167167
168- // Obtener roles del servidor (máximo 25 opciones)
169- const roles = guild . roles . cache
170- . filter ( ( r : any ) => r . id !== guild . id && ! r . managed ) // Excluir @everyone y roles de bots
168+ // Obtener roles del servidor (convertir a array correctamente)
169+ const rolesArray = Array . from (
170+ guild . roles . cache
171+ . filter ( ( r : any ) => r . id !== guild . id && ! r . managed ) // Excluir @everyone y roles de bots
172+ . values ( ) ,
173+ )
171174 . sort ( ( a : any , b : any ) => b . position - a . position )
172- . first ( 20 ) ;
175+ . slice ( 0 , 20 ) ;
173176
174177 // Crear menús para cada rol
175178 const rows = [ ] ;
@@ -179,7 +182,7 @@ async function showRolesStep(interaction: any, session: any) {
179182 . setCustomId ( `setup:role_admin:${ session . userId } ` )
180183 . setPlaceholder ( '👑 Selecciona el rol Admin' )
181184 . addOptions (
182- roles . map ( ( r : any ) =>
185+ rolesArray . map ( ( r : any ) =>
183186 new StringSelectMenuOptionBuilder ( )
184187 . setLabel ( r . name )
185188 . setValue ( r . id )
@@ -193,7 +196,7 @@ async function showRolesStep(interaction: any, session: any) {
193196 . setCustomId ( `setup:role_junta:${ session . userId } ` )
194197 . setPlaceholder ( '🎯 Selecciona el rol Junta' )
195198 . addOptions (
196- roles . map ( ( r : any ) =>
199+ rolesArray . map ( ( r : any ) =>
197200 new StringSelectMenuOptionBuilder ( )
198201 . setLabel ( r . name )
199202 . setValue ( r . id )
@@ -207,7 +210,7 @@ async function showRolesStep(interaction: any, session: any) {
207210 . setCustomId ( `setup:role_verify:${ session . userId } ` )
208211 . setPlaceholder ( '✅ Selecciona el rol Verificado (Normal)' )
209212 . addOptions (
210- roles . map ( ( r : any ) =>
213+ rolesArray . map ( ( r : any ) =>
211214 new StringSelectMenuOptionBuilder ( )
212215 . setLabel ( r . name )
213216 . setValue ( r . id )
@@ -221,7 +224,7 @@ async function showRolesStep(interaction: any, session: any) {
221224 . setCustomId ( `setup:role_verifyJaveriana:${ session . userId } ` )
222225 . setPlaceholder ( '🎓 Selecciona el rol Verificado (Javeriana)' )
223226 . addOptions (
224- roles . map ( ( r : any ) =>
227+ rolesArray . map ( ( r : any ) =>
225228 new StringSelectMenuOptionBuilder ( )
226229 . setLabel ( r . name )
227230 . setValue ( r . id )
@@ -253,11 +256,12 @@ async function showNotificationRolesStep(interaction: any, session: any) {
253256 const embed = createNotificationRolesEmbed ( session ) ;
254257 const guild = interaction . guild ;
255258
256- // Obtener roles del servidor
257- const roles = guild . roles . cache
258- . filter ( ( r : any ) => r . id !== guild . id && ! r . managed )
259+ // Obtener roles del servidor (convertir a array correctamente)
260+ const rolesArray = Array . from (
261+ guild . roles . cache . filter ( ( r : any ) => r . id !== guild . id && ! r . managed ) . values ( ) ,
262+ )
259263 . sort ( ( a : any , b : any ) => b . position - a . position )
260- . first ( 20 ) ;
264+ . slice ( 0 , 20 ) ;
261265
262266 const rows = [ ] ;
263267
@@ -270,7 +274,7 @@ async function showNotificationRolesStep(interaction: any, session: any) {
270274 . setLabel ( '⏭️ Omitir (no configurar)' )
271275 . setValue ( 'skip' )
272276 . setDefault ( ! session . config . roles . laLiga ) ,
273- ...roles . map ( ( r : any ) =>
277+ ...rolesArray . map ( ( r : any ) =>
274278 new StringSelectMenuOptionBuilder ( )
275279 . setLabel ( r . name )
276280 . setValue ( r . id )
@@ -288,7 +292,7 @@ async function showNotificationRolesStep(interaction: any, session: any) {
288292 . setLabel ( '⏭️ Omitir (no configurar)' )
289293 . setValue ( 'skip' )
290294 . setDefault ( ! session . config . roles . preParciales ) ,
291- ...roles . map ( ( r : any ) =>
295+ ...rolesArray . map ( ( r : any ) =>
292296 new StringSelectMenuOptionBuilder ( )
293297 . setLabel ( r . name )
294298 . setValue ( r . id )
@@ -306,7 +310,7 @@ async function showNotificationRolesStep(interaction: any, session: any) {
306310 . setLabel ( '⏭️ Omitir (no configurar)' )
307311 . setValue ( 'skip' )
308312 . setDefault ( ! session . config . roles . cursos ) ,
309- ...roles . map ( ( r : any ) =>
313+ ...rolesArray . map ( ( r : any ) =>
310314 new StringSelectMenuOptionBuilder ( )
311315 . setLabel ( r . name )
312316 . setValue ( r . id )
@@ -324,7 +328,7 @@ async function showNotificationRolesStep(interaction: any, session: any) {
324328 . setLabel ( '⏭️ Omitir (no configurar)' )
325329 . setValue ( 'skip' )
326330 . setDefault ( ! session . config . roles . notificacionesGenerales ) ,
327- ...roles . map ( ( r : any ) =>
331+ ...rolesArray . map ( ( r : any ) =>
328332 new StringSelectMenuOptionBuilder ( )
329333 . setLabel ( r . name )
330334 . setValue ( r . id )
@@ -362,11 +366,16 @@ async function showChannelsStep(interaction: any, session: any) {
362366 const embed = createChannelsEmbed ( session ) ;
363367 const guild = interaction . guild ;
364368
365- // Obtener canales de texto
366- const textChannels = guild . channels . cache
367- . filter ( ( c : any ) => c . type === ChannelType . GuildText )
369+ // Obtener canales de texto y anuncios (convertir a array correctamente)
370+ const textChannelsArray = Array . from (
371+ guild . channels . cache
372+ . filter (
373+ ( c : any ) => c . type === ChannelType . GuildText || c . type === ChannelType . GuildAnnouncement ,
374+ )
375+ . values ( ) ,
376+ )
368377 . sort ( ( a : any , b : any ) => a . position - b . position )
369- . first ( 20 ) ;
378+ . slice ( 0 , 20 ) ;
370379
371380 const rows = [ ] ;
372381
@@ -375,7 +384,7 @@ async function showChannelsStep(interaction: any, session: any) {
375384 . setCustomId ( `setup:channel_welcome:${ session . userId } ` )
376385 . setPlaceholder ( '👋 Selecciona canal de Bienvenida' )
377386 . addOptions (
378- textChannels . map ( ( c : any ) =>
387+ textChannelsArray . map ( ( c : any ) =>
379388 new StringSelectMenuOptionBuilder ( )
380389 . setLabel ( `# ${ c . name } ` )
381390 . setValue ( c . id )
@@ -389,7 +398,7 @@ async function showChannelsStep(interaction: any, session: any) {
389398 . setCustomId ( `setup:channel_ticketTrigger:${ session . userId } ` )
390399 . setPlaceholder ( '🎫 Selecciona canal de Tickets' )
391400 . addOptions (
392- textChannels . map ( ( c : any ) =>
401+ textChannelsArray . map ( ( c : any ) =>
393402 new StringSelectMenuOptionBuilder ( )
394403 . setLabel ( `# ${ c . name } ` )
395404 . setValue ( c . id )
@@ -403,7 +412,7 @@ async function showChannelsStep(interaction: any, session: any) {
403412 . setCustomId ( `setup:channel_announcements:${ session . userId } ` )
404413 . setPlaceholder ( '📢 Selecciona canal de Anuncios' )
405414 . addOptions (
406- textChannels . map ( ( c : any ) =>
415+ textChannelsArray . map ( ( c : any ) =>
407416 new StringSelectMenuOptionBuilder ( )
408417 . setLabel ( `# ${ c . name } ` )
409418 . setValue ( c . id )
@@ -439,26 +448,53 @@ async function showVoiceStep(interaction: any, session: any) {
439448 const embed = createVoiceEmbed ( session ) ;
440449 const guild = interaction . guild ;
441450
442- // Obtener canales de voz
443- const voiceChannels = guild . channels . cache
444- . filter ( ( c : any ) => c . type === ChannelType . GuildVoice )
451+ // Obtener canales de voz (convertir a array correctamente)
452+ const voiceChannelsArray = Array . from (
453+ guild . channels . cache . filter ( ( c : any ) => c . type === ChannelType . GuildVoice ) . values ( ) ,
454+ )
445455 . sort ( ( a : any , b : any ) => a . position - b . position )
446- . first ( 20 ) ;
456+ . slice ( 0 , 20 ) ;
447457
448- // Obtener categorías
449- const categories = guild . channels . cache
450- . filter ( ( c : any ) => c . type === ChannelType . GuildCategory )
458+ // Obtener categorías (convertir a array correctamente)
459+ const categoriesArray = Array . from (
460+ guild . channels . cache . filter ( ( c : any ) => c . type === ChannelType . GuildCategory ) . values ( ) ,
461+ )
451462 . sort ( ( a : any , b : any ) => a . position - b . position )
452- . first ( 20 ) ;
463+ . slice ( 0 , 20 ) ;
453464
454465 const rows = [ ] ;
455466
467+ // Validar que haya canales de voz
468+ if ( voiceChannelsArray . length === 0 ) {
469+ await interaction . update ( {
470+ embeds : [ embed ] ,
471+ components : [
472+ new ActionRowBuilder < ButtonBuilder > ( ) . addComponents (
473+ new ButtonBuilder ( )
474+ . setCustomId ( `setup:back_channels:${ session . userId } ` )
475+ . setLabel ( '← Atrás: Canales' )
476+ . setStyle ( ButtonStyle . Secondary ) ,
477+ new ButtonBuilder ( )
478+ . setCustomId ( `setup:cancel:${ session . userId } ` )
479+ . setLabel ( 'Cancelar' )
480+ . setStyle ( ButtonStyle . Danger ) ,
481+ ) ,
482+ ] ,
483+ } ) ;
484+ await interaction . followUp ( {
485+ content :
486+ '❌ No se encontraron canales de voz en este servidor. Crea al menos un canal de voz antes de continuar.' ,
487+ flags : 1 << 6 ,
488+ } ) ;
489+ return ;
490+ }
491+
456492 // Canal VC Create
457493 const vcCreateMenu = new StringSelectMenuBuilder ( )
458494 . setCustomId ( `setup:channel_vcCreate:${ session . userId } ` )
459495 . setPlaceholder ( '🎤 Selecciona canal VC Create' )
460496 . addOptions (
461- voiceChannels . map ( ( c : any ) =>
497+ voiceChannelsArray . map ( ( c : any ) =>
462498 new StringSelectMenuOptionBuilder ( )
463499 . setLabel ( `🔊 ${ c . name } ` )
464500 . setValue ( c . id )
@@ -468,27 +504,29 @@ async function showVoiceStep(interaction: any, session: any) {
468504 rows . push ( new ActionRowBuilder < StringSelectMenuBuilder > ( ) . addComponents ( vcCreateMenu ) ) ;
469505
470506 // Categoría Voz
471- const voiceCategoryMenu = new StringSelectMenuBuilder ( )
472- . setCustomId ( `setup:channel_voiceCategory:${ session . userId } ` )
473- . setPlaceholder ( '📁 Selecciona categoría de Voz' )
474- . addOptions (
475- categories . map ( ( c : any ) =>
476- new StringSelectMenuOptionBuilder ( )
477- . setLabel ( `📁 ${ c . name } ` )
478- . setValue ( c . id )
479- . setDefault ( session . config . channels . voiceCategory === c . id ) ,
480- ) ,
481- ) ;
482- rows . push ( new ActionRowBuilder < StringSelectMenuBuilder > ( ) . addComponents ( voiceCategoryMenu ) ) ;
507+ if ( categoriesArray . length > 0 ) {
508+ const voiceCategoryMenu = new StringSelectMenuBuilder ( )
509+ . setCustomId ( `setup:channel_voiceCategory:${ session . userId } ` )
510+ . setPlaceholder ( '📁 Selecciona categoría de Voz' )
511+ . addOptions (
512+ categoriesArray . map ( ( c : any ) =>
513+ new StringSelectMenuOptionBuilder ( )
514+ . setLabel ( `📁 ${ c . name } ` )
515+ . setValue ( c . id )
516+ . setDefault ( session . config . channels . voiceCategory === c . id ) ,
517+ ) ,
518+ ) ;
519+ rows . push ( new ActionRowBuilder < StringSelectMenuBuilder > ( ) . addComponents ( voiceCategoryMenu ) ) ;
520+ }
483521
484522 // VC Pool (múltiple selección)
485523 const vcPoolMenu = new StringSelectMenuBuilder ( )
486524 . setCustomId ( `setup:vcPool:${ session . userId } ` )
487525 . setPlaceholder ( '🔄 Selecciona canales para VC Pool (mínimo 2)' )
488526 . setMinValues ( 2 )
489- . setMaxValues ( Math . min ( voiceChannels . size , 10 ) )
527+ . setMaxValues ( Math . min ( voiceChannelsArray . length , 10 ) )
490528 . addOptions (
491- voiceChannels . map ( ( c : any ) =>
529+ voiceChannelsArray . map ( ( c : any ) =>
492530 new StringSelectMenuOptionBuilder ( )
493531 . setLabel ( `🔊 ${ c . name } ` )
494532 . setValue ( c . id )
0 commit comments