How to get clean text without markdown markup?

Hello. For my bot I need to retrieve text after it is rendered with markdown. The problem is that I need to take into account character escaping and etc. How can I do this?
25 Replies
d.js toolkit
d.js toolkit•4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
ErickSkrauch
ErickSkrauch•4mo ago
I have already explained all the necessary details.
-Carlos👑
-Carlos👑•4mo ago
string manipulation is not djs, you can ask in #other-js-ts
ErickSkrauch
ErickSkrauch•4mo ago
Yea, I know. But since Discord has a pretty powerful markdown formatting system, it seems like there should be a way in the Discord.js library itself to get the plain text, since nobody but the library would know exactly how to render that markdown to get the final text.
-Carlos👑
-Carlos👑•4mo ago
what do you exactly mean by markdown? this?
ErickSkrauch
ErickSkrauch•4mo ago
Yep. When you send a message with such formatting, bot receives plain markdown: **this?**. But I need to strip somehow all those asterisks, underlines, etc., and obtain the plain text. I saw some libraries that utilize marked library in order to format text and extract plain from built HTML, but they doesn't support the whole markdown, available on Discord.
d.js docs
d.js docs•4mo ago
:property: Message#cleanContent The message contents with all mentions replaced by the equivalent text. If mentions cannot be resolved to a name, the relevant mention in the message content will not be converted.
monbrey
monbrey•4mo ago
This would be one part towards that There's isnt really a way to strip all of it otherwise, its part of the content
-Carlos👑
-Carlos👑•4mo ago
found this, haven't tried it but you can give it a try https://discord.js.org/docs/packages/formatters/0.3.3/escapeMarkdown:Function
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
monbrey
monbrey•4mo ago
That doesn't remove it
ErickSkrauch
ErickSkrauch•4mo ago
Unfortunatelly, it doesn't remove markup.
monbrey
monbrey•4mo ago
Though if you look at the source code regex used to identify it, could be a good way to implement your own
ErickSkrauch
ErickSkrauch•4mo ago
It will escape markup, but do not remove it.
monbrey
monbrey•4mo ago
Take the source code and instead of doing replacements/joins with escaped markdown, do it with nothing removed
ErickSkrauch
ErickSkrauch•4mo ago
As I mentioned, it's way more complex than simple "find double asterisk and remove it". That is the problem (
Want results from more Discord servers?
Add your server