I’m hoping I’m overlooking something simple here. I have a function that sends some debug messages to Discord in code blocks (“`). Since it can quote past messages, previous code blocks can interrupt the formatting of the new ones added by my function and break up the message into multiple code blocks at odd places, making it difficult to read.
I figured there would be a simple solution in just doing a:
msg.replace("```", "```")
but I am finding that isn’t the case. It seems that if I either add 1 or 2 backslashes in the replacement text, python always seems to add two, such that discord displays one backslash and renders the code block rather than escaping the code block as intended. Two backslashes are also present when printing the string in console.
I have tried:
msg.replace("```", "```")
msg.replace("```", "\```")
re.sub("```", "```", msg)
re.sub("```", "\```", msg)
All of these give the same result, which results in discord printing a backslash and then rendering the code block anyways.
How can I format the string such that it leaves a single escape character in the string before the code block tag?
Adam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.