package Ġme . b ard y . bot . listeners Ċ Ċ import Ġcom . moj ang . b rig ad ier . Command Dispatcher Ċ import Ġcom . moj ang . b rig ad ier . Parse Results Ċ import Ġcom . moj ang . b rig ad ier . exceptions . Command Syntax Exception Ċ import Ġme . b ard y . bot . command . Command Context Ċ import Ġnet . dv 8 tion . j da . api . events . message . guild . Guild Message Received Event Ċ import Ġnet . dv 8 tion . j da . api . hooks . Listener Adapter Ċ import Ġnet . dv 8 tion . j da . api . sharding . Shard Manager Ċ import Ġorg . springframework . cache . annotation . Cache able Ċ import Ġorg . springframework . stereotype . Component Ċ import Ġjavax . annotation . Post Construct Ċ Ċ @ Component Ċ class ĠMessage Listener ( ĊĠĠĠ Ġprivate Ġval Ġdispatcher : ĠCommand Dispatcher < Command Context >, ĊĠĠĠ Ġprivate Ġval Ġshard Manager : ĠSh ard Manager Ċ ) Ġ: ĠListener Adapter () Ġ{ ĊĊĠĠĠ Ġ@ Post Construct ĊĠĠĠ Ġfun Ġregister Self () Ġ= Ġshard Manager . addEventListener ( this ) ĊĊĠĠĠ Ġoverride Ġfun Ġon Guild Message Received ( event : ĠGuild Message Received Event ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! event . message . content Raw . startsWith (' ! ')) Ġreturn ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġevent . message . content Raw . remove Prefix (" !") ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdispatcher . execute ( parse Command ( event . build Context (), Ġmessage )) ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( exception : ĠCommand Syntax Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexception Message Ġ= Ġwhen Ġ( exception . type ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCommand Syntax Exception . BUIL T _ IN _ EXCEPTION S . dispatcher ParseException () Ġ-> Ġ" a Ġparse Ġexception " ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCommand Syntax Exception . BUIL T _ IN _ EXCEPTION S . dispatcher Unknown Argument () Ġ-> Ġ" an Ġunknown Ġargument Ġexception " ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCommand Syntax Exception . BUIL T _ IN _ EXCEPTION S . dispatcher Unknown Command () Ġ-> Ġ" an Ġunknown Ġcommand Ġexception " ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġ" Unknown Ġerror Ġwhen Ġattempting Ġto Ġexecute Ġcommand Ġ$ message " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġevent . channel . sendMessage (" I Ġseem Ġto Ġhave Ġencountered Ġ$ exception Message Ġwhen Ġtrying Ġto Ġexecute Ġthat . "). queue () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Cache able (" parse _ results ") ĊĠĠĠ Ġfun Ġparse Command ( context : ĠCommand Context , Ġcommand : ĠString ): ĠParse Results < Command Context > Ġ= Ġdispatcher . parse ( command , Ġcontext ) ĊĊĠĠĠ Ġprivate Ġfun ĠGuild Message Received Event . build Context () Ġ= ĠCommand Context ( guild , Ġchannel , Ġmember , Ġmessage ) Ċ }