Yes, all the information is passed in the raw indead.
But how can I include the channel name in the variable name?

I expect a problem with multiple channels.

like:
set %failedchan.#channel1

And if it occurs again:
set %failedchan.#channel2