Move the !delcom code above the * code. Same goes for any other text events you add.
The event catching "*" matches "!delcom" also because * matches everything. Only one matching event from each file can trigger, so if something else matches it first it will never trigger.
Editing a line is as simple as replacing it, use $readn the same as your delcom except without the d switch. Again remember to place it above the "*" event.
on *:text:!editcom & *:#: {
if ($read(commands.txt, ns, $2)) {
write -l $+ $readn commands.txt $2-
}
}