Search code examples
cssnode.jsdiscord

Color text in discord


My goal is to partly color a text. I know I can use .sendCode("css","this is my message"); which we'll make my text yellow but I don't want my whole text to be yellow.

Perhaps I could create another .css file and then call it from my JavaScript file but as I am inexperienced with JavaScript I would like some help with it. I think that's the fastest way to do it.


Solution

  • (Updated for 2022)

    In 2022's polish week, Discord added support for ansi on code blocks, previously it was not possible to display colors on the chat, however you could "mimic" colored output by selecting specific highlighted languages like prolog or css.

    To display colored text using code-blocks, you simply need to create a code block with the language set to ansi and then use any of the several ansi escape codes to style your text.

    Here is a simple example of a message which will display in red. The escape code used for ansi is \033.

    ```ansi
    [0;31m RED TEXT
    ```
    

    Do note however, that Discord does not render all colors as you would expect them, having some special issues with background colors being mostly shades of grey.

    ansi color preview on discord