Hello,
The first thing that comes to mind, is that "onchan" only works for channels added to your eggdrop's channel-list. As such, your script would then crash once your eggdrop has left the channel.
The options I see, is either to use the "inactive" channel modifier to temporarily disable the channel (rather than delete it); or if you still prefer to delete it, you'd have to use "validchan" to check whether the channel is valid, rather than using "onchan" (or "botonchan" for that matter).
The only obvious error I can see in this code, is that you've placed "else {" on a separate line.
Unlike languages like C, Java, etc; tcl is strictly newline-terminated outside blocks. As your code stands now, tcl tries to interpret "else" as a new command, as opposed to an argument to "if":
// this is ok
if {some expression} then {
code here
} else {
other code here
}
//or simplified
if {some expression} {
code here
} {
other code here
}
//or condensed
if {some expression} {code here} {other code here}
// these however will not work
if {some expression}
{
code here
}
...
// then-body is not part of the if-command due to the newline _before_ {
if {some expression} {
code here
} else
{
code here
}
// else-body is not part of the if-command due to the newline _before_ {
if {some expression} {
code here
}
else {
code here
}
// else-keyword and -body is not part of the if-command due to the newline _before_ else