This is what I'm currently using. Someone shared it on a forum, I think it was the official forums, but I cannot recall who. I've been using it for quite a long time added in one of the files for ElvUI.
Code:
SlashCmdList["CLEAR"] = function()
local s, i
s = ""
for i=1, 255, 1 do
s = s..'\r'
end
SELECTED_CHAT_FRAME:AddMessage(s)
end