@@ -107,24 +107,39 @@ internal class MessageHandler(
107107 ).apply { action = botInstance.action }
108108 msg.sender = newSenderWithGroupId
109109 if (msg.groupId !in botInstance.listenedGroups && botInstance.listenedGroups.isNotEmpty()) return
110- botInstance.dispatchEvent(GroupMessageEvent (botInstance.action, msg))
111- listener.onGroupMessage(msg)
112- OneBotFactory .commandManager.handleGroup(msg)
110+ try {
111+ botInstance.dispatchEvent(GroupMessageEvent (botInstance.action, msg))
112+ listener.onGroupMessage(msg)
113+ OneBotFactory .commandManager.handleGroup(msg)
114+ } catch (e: Exception ) {
115+ @Suppress(" LocalVariableName" )
116+ val _event = GroupMessageErrorEvent (botInstance.action, msg, e)
117+ botInstance.dispatchEvent(_event )
118+ listener.onGroupMessageError(_event )
119+ }
113120 }
114121
115122 InboundMessageType .private -> {
116123 val msg = message.fromJson<PrivateMessage >()
117124 msg.sessionId = Uuid .random()
118125 msg.action = botInstance.action
119126 msg.sender.action = botInstance.action
120- botInstance.dispatchEvent(PrivateMessageEvent (botInstance.action, msg))
121- listener.onPrivateMessage(msg)
122- OneBotFactory .commandManager.handlePrivate(msg)
127+ try {
128+ botInstance.dispatchEvent(PrivateMessageEvent (botInstance.action, msg))
129+ listener.onPrivateMessage(msg)
130+ OneBotFactory .commandManager.handlePrivate(msg)
131+ } catch (e: Exception ) {
132+ @Suppress(" LocalVariableName" )
133+ val _event = PrivateMessageErrorEvent (botInstance.action, msg, e)
134+ botInstance.dispatchEvent(_event )
135+ listener.onPrivateMessageError(_event )
136+ }
123137 }
124138
125139 null -> listener.onRawMessage(botInstance.action, message)
126140 }
127141 return
142+
128143 }
129144
130145 if (serializedMessage.postType == PostType .request) {
0 commit comments