That message isn't an internal mIRC error. When you execute a command mIRC does the following:
a) Checks for an alias with that name and executes it.
Or if not:
b) Checks for a built-in command with that name and executes it
Or if not:
c) Sends it to the server.

If there's no such command recognised by the server then it will respond with raw 421 (ERR_UNKNOWNCOMMAND), which is what you see in the status window. So in answer to your question you need to use a raw event to catch 421.

If you don't want it to get to the stage where it sends it to the server in the first place then you'd need to perform the checks mentioned above yourself. You can use $isalias() for the first check, unfortunately there's no easy way to check for built-ins so you'd probably have to check against a hardcoded list of existing commands in your script.


Spelling mistakes, grammatical errors, and stupid comments are intentional.