Makes sure when database is empty, the bot does not crash.

Previous if the database was empty then the bot would crash trying to sort "undefined", this check fixes that problem by replacing undefined with an empty list in appropriate places.