@@ -68,30 +68,7 @@ const { ComponentType } = require('discord-api-types/v10');
68
68
* @ignore
69
69
*/
70
70
function createComponent ( data ) {
71
- if ( data instanceof Component ) {
72
- return data ;
73
- }
74
-
75
- switch ( data . type ) {
76
- case ComponentType . ActionRow :
77
- return new ActionRow ( data ) ;
78
- case ComponentType . Button :
79
- return new ButtonComponent ( data ) ;
80
- case ComponentType . StringSelect :
81
- return new StringSelectMenuComponent ( data ) ;
82
- case ComponentType . TextInput :
83
- return new TextInputComponent ( data ) ;
84
- case ComponentType . UserSelect :
85
- return new UserSelectMenuComponent ( data ) ;
86
- case ComponentType . RoleSelect :
87
- return new RoleSelectMenuComponent ( data ) ;
88
- case ComponentType . MentionableSelect :
89
- return new MentionableSelectMenuComponent ( data ) ;
90
- case ComponentType . ChannelSelect :
91
- return new ChannelSelectMenuComponent ( data ) ;
92
- default :
93
- return new Component ( data ) ;
94
- }
71
+ return data instanceof Component ? data : new ( ComponentTypeToClass [ data . type ] ?? Component ) ( data ) ;
95
72
}
96
73
97
74
exports . createComponent = createComponent ;
@@ -105,3 +82,14 @@ const { RoleSelectMenuComponent } = require('../structures/RoleSelectMenuCompone
105
82
const { StringSelectMenuComponent } = require ( '../structures/StringSelectMenuComponent.js' ) ;
106
83
const { TextInputComponent } = require ( '../structures/TextInputComponent.js' ) ;
107
84
const { UserSelectMenuComponent } = require ( '../structures/UserSelectMenuComponent.js' ) ;
85
+
86
+ const ComponentTypeToClass = {
87
+ [ ComponentType . ActionRow ] : ActionRow ,
88
+ [ ComponentType . Button ] : ButtonComponent ,
89
+ [ ComponentType . StringSelect ] : StringSelectMenuComponent ,
90
+ [ ComponentType . TextInput ] : TextInputComponent ,
91
+ [ ComponentType . UserSelect ] : UserSelectMenuComponent ,
92
+ [ ComponentType . RoleSelect ] : RoleSelectMenuComponent ,
93
+ [ ComponentType . MentionableSelect ] : MentionableSelectMenuComponent ,
94
+ [ ComponentType . ChannelSelect ] : ChannelSelectMenuComponent ,
95
+ } ;
0 commit comments