diff --git a/source/TitleState.hx b/source/TitleState.hx
index c91dc54eb..e643ac1a8 100644
--- a/source/TitleState.hx
+++ b/source/TitleState.hx
@@ -96,6 +96,10 @@ class TitleState extends MusicBeatState
 
 		#if desktop
 		DiscordClient.initialize();
+		
+		Application.current.onExit.add (function (exitCode) {
+			DiscordClient.shutdown();
+		 });
 		#end
 	}