6
6
import team .unnamed .commandflow .exception .CommandException ;
7
7
import net .dv8tion .jda .api .entities .Member ;
8
8
import net .dv8tion .jda .api .entities .Message ;
9
- import net .dv8tion .jda .api .entities .TextChannel ;
10
9
import net .dv8tion .jda .api .entities .User ;
11
- import net .dv8tion .jda .api .events .message .guild .GuildMessageReceivedEvent ;
10
+ import net .dv8tion .jda .api .entities .channel .concrete .PrivateChannel ;
11
+ import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
12
+ import net .dv8tion .jda .api .events .message .MessageReceivedEvent ;
12
13
import net .dv8tion .jda .api .hooks .ListenerAdapter ;
13
14
import net .kyori .adventure .text .Component ;
14
15
@@ -23,11 +24,16 @@ public MessageListener(CommandManager commandManager, String commandPrefix) {
23
24
}
24
25
25
26
@ Override
26
- public void onGuildMessageReceived (GuildMessageReceivedEvent event ) {
27
+ public void onMessageReceived (MessageReceivedEvent event ) {
28
+
29
+ if (!(event .getChannel () instanceof TextChannel )){
30
+ return ;
31
+ }
32
+
27
33
Member member = event .getMember ();
28
34
User user = event .getAuthor ();
29
35
Message message = event .getMessage ();
30
- TextChannel channel = event .getChannel ();
36
+ TextChannel channel = event .getChannel (). asTextChannel () ;
31
37
32
38
String rawMessage = event .getMessage ().getContentRaw ();
33
39
@@ -37,7 +43,11 @@ public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
37
43
38
44
rawMessage = rawMessage .substring (commandPrefix .length ());
39
45
40
- String label = rawMessage .substring (0 , rawMessage .indexOf (" " ));
46
+ String label = rawMessage ;
47
+
48
+ if (label .indexOf (" " ) > 0 ){
49
+ label = rawMessage .substring (0 , rawMessage .indexOf (" " ));
50
+ }
41
51
42
52
Namespace namespace = Namespace .create ();
43
53
@@ -48,7 +58,7 @@ public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
48
58
namespace .setObject (String .class , "label" , label );
49
59
50
60
try {
51
- commandManager .execute (namespace , rawMessage . substring ( commandPrefix . length ()) );
61
+ commandManager .execute (namespace , rawMessage );
52
62
} catch (CommandException e ) {
53
63
CommandException exceptionToSend = e ;
54
64
0 commit comments