I found a function, that will kill all buffers except the current buffer that's open.

(defun kill-other-buffers ()
"Kill all buffers but the current one.
Doesn't mess with special buffers."
(interactive)
(when (y-or-n-p "Are you sure you want to kill all buffers but the current one? ")
(seq-each
#'kill-buffer
(delete (current-buffer) (seq-filter #'buffer-file-name (buffer-list))))))

It works great. However, when I have two windows open with a different buffer in each window, I noticed it kills the visible buffer in the other window too, except for the buffer where the cursor currently in is.

I studied the manuals of Emacs, in order to detect the open buffers that are visible in all windows. But I found not one. So I'm wondering if anyone have a good suggestion for this?

I might be mistaken, but when I add your first suggestion and then the second suggestion. They also kill the visible buffers in the other windows. So I wondered if you tried the function kill-other-buffers itself with the buflist modification?
– ReneFrogerMay 4 '17 at 13:33

Each of my suggestions produces the list of buffers to kill (if substituted into your original code). You can trivially test each suggestion with M-: and confirm whether the resulting list includes any of the visible buffers. I've just tested your kill-other-buffers function with one of my alternatives, and for me it's working as I expected.
– philsMay 5 '17 at 12:41

One question, I wondered how I could kill with the same function special buffers like Buffer list as well? I noticed they don't get killed (Buffer list, Magit status window, helm, etc).
– ReneFrogerMay 10 '17 at 8:00

n.b. That behaviour is based on your original code, which filters the list of candidates to only those which are visiting a file -- for which (buffer-file-name BUFFER) returns non-nil.
– philsMay 10 '17 at 9:21