I've realized a critical matter with this snippet. For the quit and nick event, the $chan doesn't exist and it'll only return $null.