@@ -9,9 +9,10 @@ const { readFileSync } = require("fs");
99module . exports = {
1010 name : "update" ,
1111 verificationCommand : true ,
12+ requiresBot : true ,
1213 description : "Update your current roles" ,
1314
14- execute : async ( interaction , user ) => {
15+ execute : async ( interaction , user = undefined , unverify = false ) => {
1516 try {
1617 const linkedData = readFileSync ( "data/linked.json" ) ;
1718 if ( ! linkedData ) {
@@ -39,22 +40,31 @@ module.exports = {
3940 const roles = [
4041 config . verification . verifiedRole ,
4142 config . verification . guildMemberRole ,
42- ...config . verification . ranks . map ( ( r ) => r . role ) ,
43+ ...config . verification . ranks . flatMap ( ( r ) => r . roles ) ,
4344 ] ;
4445
4546 for ( const role of roles ) {
4647 if ( role === config . verification . verifiedRole && config . verification . removeVerificationRole === false ) {
4748 continue ;
4849 }
4950
51+ if ( role === config . verification . unverifiedRole ) {
52+ continue ;
53+ }
54+
5055 if ( interaction . member . roles . cache . has ( role ) ) {
5156 await interaction . member . roles . remove ( role , "Updated Roles" ) ;
5257 }
5358 }
5459
60+ if ( ! interaction . member . roles . cache . has ( config . verification . unverifiedRole ) ) {
61+ await interaction . member . roles . add ( config . verification . unverifiedRole , "Updated Roles" ) ;
62+ }
63+
5564 interaction . member . setNickname ( null , "Updated Roles" ) ;
5665
57- throw new HypixelDiscordChatBridgeError ( "You are not linked to a Minecraft account." ) ;
66+ if ( unverify === false ) throw new HypixelDiscordChatBridgeError ( "You are not linked to a Minecraft account." ) ;
67+ return ;
5868 }
5969
6070 if ( ! interaction . member . roles . cache . has ( config . verification . verifiedRole ) ) {
@@ -77,13 +87,17 @@ module.exports = {
7787 if ( config . verification . ranks . length > 0 && guildMember . rank ) {
7888 const rank = config . verification . ranks . find ( ( r ) => r . name . toLowerCase ( ) == guildMember . rank . toLowerCase ( ) ) ;
7989 if ( rank ) {
80- for ( const role of config . verification . ranks ) {
81- if ( interaction . member . roles . cache . has ( role . role ) ) {
82- await interaction . member . roles . remove ( role . role , "Updated Roles" ) ;
90+ for ( const rankRole of config . verification . ranks ) {
91+ for ( const role of rankRole . roles ) {
92+ if ( interaction . member . roles . cache . has ( role ) ) {
93+ await interaction . member . roles . remove ( role , "Updated Roles" ) ;
94+ }
8395 }
8496 }
8597
86- await interaction . member . roles . add ( rank . role , "Updated Roles" ) ;
98+ for ( const role of rank . roles ) {
99+ await interaction . member . roles . add ( role , "Updated Roles" ) ;
100+ }
87101 }
88102 }
89103 } else {
0 commit comments