@@ -95,85 +95,85 @@ export default new Command({
9595
9696 const sub = interaction . options . getSubcommand ( ) ;
9797
98- if ( sub === "create" ) {
99- if ( boosterRecord . customRole ) {
100- await interaction . reply (
101- componentsV2 ( [
102- "You already have a custom role." ,
103- "Use `/role edit` to change it." ,
104- ] )
105- ) ;
106- return ;
107- }
108-
109- const name = interaction . options . getString ( "name" , true ) ;
110- const color = interaction . options . getString ( "color" , true ) ;
111-
112- if ( ! / ^ # [ 0 - 9 a - f A - F ] { 6 } $ / . test ( color ) ) {
113- await interaction . reply (
114- componentsV2 ( [
115- "Invalid color." ,
116- "Use a hex color like `#ff0000`." ,
117- ] )
118- ) ;
119- return ;
120- }
121-
122- await interaction . deferReply ( { flags : MessageFlags . Ephemeral } ) ;
123-
124- const role = await createCustomRole ( guild , member , name , color as ColorResolvable ) ;
125-
126- await interaction . editReply (
127- componentsV2 ( [ `**Custom role created!**` , `${ role } is ready to use.` ] )
128- ) ;
129- return ;
130- }
131-
132- if ( sub === "edit" ) {
133- if ( ! boosterRecord . customRole ?. discordRoleId ) {
134- await interaction . reply (
135- componentsV2 ( [ "You don't have a custom role yet." , "Use `/role create` first." ] )
136- ) ;
137- return ;
138- }
139-
140- const name = interaction . options . getString ( "name" ) ?? undefined ;
141- const color = ( interaction . options . getString ( "color" ) ?? undefined ) as ColorResolvable | undefined ;
142-
143- if ( color && ! / ^ # [ 0 - 9 a - f A - F ] { 6 } $ / . test ( color as string ) ) {
144- await interaction . reply (
145- componentsV2 ( [
146- "Invalid color." ,
147- "Use a hex color like `#ff0000`." ,
148- ] )
149- ) ;
150- return ;
151- }
152-
153- await interaction . deferReply ( { flags : MessageFlags . Ephemeral } ) ;
98+ switch ( sub ) {
99+ case "create" : {
100+ if ( boosterRecord . customRole ) {
101+ await interaction . reply (
102+ componentsV2 ( [
103+ "You already have a custom role." ,
104+ "Use `/role edit` to change it." ,
105+ ] )
106+ ) ;
107+ return ;
108+ }
109+
110+ const name = interaction . options . getString ( "name" , true ) ;
111+ const color = interaction . options . getString ( "color" , true ) ;
112+
113+ if ( ! / ^ # [ 0 - 9 a - f A - F ] { 6 } $ / . test ( color ) ) {
114+ await interaction . reply (
115+ componentsV2 ( [
116+ "Invalid color." ,
117+ "Use a hex color like `#ff0000`." ,
118+ ] )
119+ ) ;
120+ return ;
121+ }
122+
123+ await interaction . deferReply ( { flags : MessageFlags . Ephemeral } ) ;
124+
125+ const role = await createCustomRole ( guild , member , name , color as ColorResolvable ) ;
154126
155- const role = await updateCustomRole ( guild , interaction . user . id , name , color ) ;
156- if ( ! role ) {
157127 await interaction . editReply (
158- componentsV2 ( [ "Couldn't update that role." , "It may have been deleted manually." ] )
128+ componentsV2 ( [ `**Custom role created!**` , ` ${ role } is ready to use.` ] )
159129 ) ;
160- return ;
130+ break ;
161131 }
162-
163- await interaction . editReply ( componentsV2 ( [ "**Custom role updated.**" ] ) ) ;
164- return ;
165- }
166-
167- if ( sub === "delete" ) {
168- if ( ! boosterRecord . customRole ?. discordRoleId ) {
169- await interaction . reply ( componentsV2 ( [ "You don't have a custom role to delete." ] ) ) ;
132+ case "edit" : {
133+ if ( ! boosterRecord . customRole ?. discordRoleId ) {
134+ await interaction . reply (
135+ componentsV2 ( [ "You don't have a custom role yet." , "Use `/role create` first." ] )
136+ ) ;
137+ return ;
138+ }
139+
140+ const name = interaction . options . getString ( "name" ) ?? undefined ;
141+ const color = ( interaction . options . getString ( "color" ) ?? undefined ) as ColorResolvable | undefined ;
142+
143+ if ( color && ! / ^ # [ 0 - 9 a - f A - F ] { 6 } $ / . test ( color as string ) ) {
144+ await interaction . reply (
145+ componentsV2 ( [
146+ "Invalid color." ,
147+ "Use a hex color like `#ff0000`." ,
148+ ] )
149+ ) ;
150+ return ;
151+ }
152+
153+ await interaction . deferReply ( { flags : MessageFlags . Ephemeral } ) ;
154+
155+ const role = await updateCustomRole ( guild , interaction . user . id , name , color ) ;
156+ if ( ! role ) {
157+ await interaction . editReply (
158+ componentsV2 ( [ "Couldn't update that role." , "It may have been deleted manually." ] )
159+ ) ;
160+ return ;
161+ }
162+
163+ await interaction . editReply ( componentsV2 ( [ "**Custom role updated.**" ] ) ) ;
164+ break ;
165+ }
166+ case "delete" : {
167+ if ( ! boosterRecord . customRole ?. discordRoleId ) {
168+ await interaction . reply ( componentsV2 ( [ "You don't have a custom role to delete." ] ) ) ;
169+ return ;
170+ }
171+
172+ await interaction . deferReply ( { flags : MessageFlags . Ephemeral } ) ;
173+ await deleteCustomRole ( guild , interaction . user . id ) ;
174+ await interaction . editReply ( componentsV2 ( [ "**Custom role deleted.**" ] ) ) ;
170175 return ;
171176 }
172-
173- await interaction . deferReply ( { flags : MessageFlags . Ephemeral } ) ;
174- await deleteCustomRole ( guild , interaction . user . id ) ;
175- await interaction . editReply ( componentsV2 ( [ "**Custom role deleted.**" ] ) ) ;
176- return ;
177177 }
178178 } ,
179179} )
0 commit comments