I can't bother to search at the moment, but I know that there are already dedicated Messenger Plus! scripts/snippets which can do this.
There are also some schedular scripts where you can use commands.
And there is also the Exit Messenger script which I once made which extends the use of the /Signout command with a delay (made because of the exact same request someone once made).
happy hunting