If you haven't already, to help with debugging in-game, install both
BugGrabber and
BugSack
As to the code, SendMessage isn't a lua or WoW API function, except as a method of the
C_Club system. Maybe it's a custom function in another addon?
To send text directly to the chatframe you can replace the SendMessage(...) lines with
print(...)