I would like to close Discord programmatically, in a proper way (without calling Process.Kill()).
AFAIK the usual way to close a program elegantly is to check if there is a main window associated to the process (eg : Process.MainWindowHandle != IntPtr.Zero) and then call Process.CloseMainWindow(). It will send a close message to the main window.
It does not work with Discord as the main window might be already closed, with the program still running in background. The usual way to exit Discord is to right click on the task bar icon and choose "Quit Discord" not just closing the main window.
When Windows is shutting down, Discord close itself automatically. I don't think Windows simply kill all Discord processes so maybe there a way to do something similar to what Windows does ?