@@ -89,11 +89,13 @@ public void connect(CommandSender sender) {
89
89
}
90
90
91
91
this .plugin .getLogger ().info (this .plugin .getLang ().getMessage ("logger.info.bot-connecting" ));
92
- Player tokenManager = null ;
92
+ Player tokenManager ;
93
93
if (sender instanceof Player ) {
94
94
tokenManager = (Player ) sender ;
95
95
this .tokenManagerId = tokenManager .getUniqueId ().toString ();
96
96
tokenManager .sendMessage (this .plugin .getLang ().getMessage ("chat.configuration.bot-connecting" ));
97
+ } else {
98
+ tokenManager = null ;
97
99
}
98
100
99
101
byte [] base64TokenBytes ;
@@ -107,17 +109,20 @@ public void connect(CommandSender sender) {
107
109
base64TokenBytes = new byte [0 ];
108
110
}
109
111
110
- try {
111
- this .jda = JDABuilder .createDefault (new String (base64TokenBytes ))
112
- .addEventListeners (new ReadyListener (this .plugin ))
113
- .build ();
114
- } catch (InvalidTokenException | IllegalArgumentException e ) {
115
- this .plugin .getLogger ().severe (this .plugin .getLang ().getMessage ("logger.error.bot-could-not-connect" ));
116
- this .plugin .getConfigYamlFile ().remove (ConfigField .TOKEN .toString ());
117
- if (tokenManager != null ) {
118
- tokenManager .sendMessage (this .plugin .getLang ().getMessage ("chat.configuration.bot-could-not-connect" ));
112
+ byte [] finalBase64TokenBytes = base64TokenBytes ;
113
+ this .plugin .getServer ().getScheduler ().runTaskAsynchronously (this .plugin , () -> {
114
+ try {
115
+ this .jda = JDABuilder .createDefault (new String (finalBase64TokenBytes ))
116
+ .addEventListeners (new ReadyListener (this .plugin ))
117
+ .build ();
118
+ } catch (InvalidTokenException | IllegalArgumentException e ) {
119
+ this .plugin .getLogger ().severe (this .plugin .getLang ().getMessage ("logger.error.bot-could-not-connect" ));
120
+ this .plugin .getConfigYamlFile ().remove (ConfigField .TOKEN .toString ());
121
+ if (tokenManager != null ) {
122
+ tokenManager .sendMessage (this .plugin .getLang ().getMessage ("chat.configuration.bot-could-not-connect" ));
123
+ }
119
124
}
120
- }
125
+ });
121
126
}
122
127
123
128
public boolean isAdministrator () {
0 commit comments