import hexchat

__module_name__ = "Detach"
__module_author__ = "Poorchop"
__module_version__ = "0.1"
__module_description__ = "Detach and close the current channel on ZNC with a simple /detach"

detached = False


def detach_cb(word, word_eol, userdata):
    global detached

    if detached or len(word) > 1:
        return
    else:
        chan = hexchat.get_info("channel")
        detached = True
        hexchat.command("DETACH {}".format(chan))
        detached = False

    return hexchat.EAT_ALL


hexchat.hook_command("DETACH", detach_cb)

hexchat.prnt(__module_name__ + " version " + __module_version__ + " loaded")

@@ -188,34 +188,16 @@
 etach%22%0A%0A
-detached = False%0A%0A
 %0Adef det
@@ -238,43 +238,10 @@
     
-global detached%0A%0A    if detached or
+if
  len
@@ -324,32 +324,8 @@
 l%22)%0A
-        detached = True%0A
     
@@ -341,24 +341,30 @@
 at.command(%22
+QUOTE 
 DETACH %7B%7D%22.f
@@ -379,33 +379,8 @@
 an))
-%0A        detached = False
 %0A%0A  

Update detach.py