Skip to content

Instantly share code, notes, and snippets.

@kkrypt0nn
Last active July 11, 2026 15:20
Show Gist options
  • Select an option

  • Save kkrypt0nn/a02506f3712ff2d1c8ca7c9e0aed7c06 to your computer and use it in GitHub Desktop.

Select an option

Save kkrypt0nn/a02506f3712ff2d1c8ca7c9e0aed7c06 to your computer and use it in GitHub Desktop.
A guide to ANSI on Discord

A guide to ANSI on Discord

Discord is now slowly rolling out the ability to send colored messages within code blocks. It uses the ANSI color codes, so if you've tried to print colored text in your terminal or console with Python or other languages then it will be easy for you.

Quick Explanation

To be able to send a colored text, you need to use the ansi language for your code block and provide a prefix of this format before writing your text:

\u001b[{format};{color}m

Important

\u001b is the unicode escape for ESCAPE/ESC, meant to be used in the source of your bot (see http://www.unicode-symbol.com/u/001B.html). If you wish to send colored text without using your bot you need to copy the character from the website.

After you've written this, you can now type the text you wish to color. If you want to reset the color back to normal, then you need to use the \u001b[0m prefix again.

Formats

Here is the list of values you can use to replace {format}

  • 0: Normal
  • 1: Bold
  • 4: Underline

Colors

Here is the list of values you can use to replace {color}:

Text Colors

  • 30: Gray
  • 31: Red
  • 32: Green
  • 33: Yellow
  • 34: Blue
  • 35: Pink
  • 36: Cyan
  • 37: White

Background Colors

  • 40: Black
  • 41: Red
  • 42: Green
  • 43: Yellow
  • 44: Blue
  • 45: Pink
  • 46: Cyan
  • 47: White

Example

Let's take an example, I want a bold green colored text with the firefly dark blue background. I simply use \u001b[0;40m (background color) and \u001b[1;32m (text color) as prefix. Note that the order is important, first you give the background color and then the text color.

Alternatively you can also directly combine them into a single prefix like the following: \u001b[1;40;32m and you can also use multiple values. Something like \u001b[1;40;4;32m would underline the text, make it bold, make it green and have a dark blue background.

Result:

Background and text color

Raw message used:

```ansi
\u001b[0;40m\u001b[1;32mThat's some cool formatted text right?\u001b[0m
or
\u001b[1;40;32mThat's some cool formatted text right?\u001b[0m
```

ANSI Colors Showcase

The way the colors and different formats look like on Discord is shown here

ANSI Colors

Disclaimer

Note: The change has been brought to all stable desktop clients. Since syntax highlighting on mobile is far behind, ANSI is not supported on mobile as well. Refer to this gist for other syntax highlighting methods.

ANSI Colors Showcase

This is a small gist to show how I've made the picture showcasing the different ANSI formats above.

Important

\u001b is the unicode escape for ESCAPE/ESC, meant to be used in the source of your bot (see http://www.unicode-symbol.com/u/001B.html). If you wish to send colored text without using your bot you need to copy the character from the website.


Example

\u001b[1;40;32mThat's some cool formatted text, right?

Color Names

\u001b[0;30mBlack\u001b[0;0m
\u001b[0;31mRed\u001b[0;0m
\u001b[0;32mGreen\u001b[0;0m
\u001b[0;33mYellow\u001b[0;0m
\u001b[0;34mBlue\u001b[0;0m
\u001b[0;35mPink\u001b[0;0m
\u001b[0;36mCyan\u001b[0;0m
\u001b[0;37mWhite\u001b[0;0m
\u001b[0;40mBlack background\u001b[0;0m
\u001b[0;41mRed background\u001b[0;0m
\u001b[0;42mGreen background\u001b[0;0m
\u001b[0;43mYellow background\u001b[0;0m
\u001b[0;44mBlue background\u001b[0;0m
\u001b[0;45mPink background\u001b[0;0m
\u001b[0;46mCyan background\u001b[0;0m
\u001b[0;47mWhite background\u001b[0;0m

Colors

\u001b[0;30mExample\u001b[0;0m \u001b[0;31mExample\u001b[0;0m \u001b[0;32mExample\u001b[0;0m \u001b[0;33mExample\u001b[0;0m \u001b[0;34mExample\u001b[0;0m \u001b[0;35mExample\u001b[0;0m \u001b[0;36mExample\u001b[0;0m \u001b[0;37mExample\u001b[0;0m

Backgrounds

\u001b[0;40mExample\u001b[0;0m \u001b[0;41mExample\u001b[0;0m \u001b[0;42mExample\u001b[0;0m \u001b[0;43mExample\u001b[0;0m \u001b[0;44mExample\u001b[0;0m \u001b[0;45mExample\u001b[0;0m \u001b[0;46mExample\u001b[0;0m \u001b[0;47mExample\u001b[0;0m

Backgrounds & Colors

\u001b[0;40;30mExample\u001b[0;0m \u001b[0;40;31mExample\u001b[0;0m \u001b[0;40;32mExample\u001b[0;0m \u001b[0;40;33mExample\u001b[0;0m \u001b[0;40;34mExample\u001b[0;0m \u001b[0;40;35mExample\u001b[0;0m \u001b[0;40;36mExample\u001b[0;0m \u001b[0;40;37mExample\u001b[0;0m
\u001b[0;41;30mExample\u001b[0;0m \u001b[0;41;31mExample\u001b[0;0m \u001b[0;41;32mExample\u001b[0;0m \u001b[0;41;33mExample\u001b[0;0m \u001b[0;41;34mExample\u001b[0;0m \u001b[0;41;35mExample\u001b[0;0m \u001b[0;41;36mExample\u001b[0;0m \u001b[0;41;37mExample\u001b[0;0m
\u001b[0;42;30mExample\u001b[0;0m \u001b[0;42;31mExample\u001b[0;0m \u001b[0;42;32mExample\u001b[0;0m \u001b[0;42;33mExample\u001b[0;0m \u001b[0;42;34mExample\u001b[0;0m \u001b[0;42;35mExample\u001b[0;0m \u001b[0;42;36mExample\u001b[0;0m \u001b[0;42;37mExample\u001b[0;0m
\u001b[0;43;30mExample\u001b[0;0m \u001b[0;43;31mExample\u001b[0;0m \u001b[0;43;32mExample\u001b[0;0m \u001b[0;43;33mExample\u001b[0;0m \u001b[0;43;34mExample\u001b[0;0m \u001b[0;43;35mExample\u001b[0;0m \u001b[0;43;36mExample\u001b[0;0m \u001b[0;43;37mExample\u001b[0;0m
\u001b[0;44;30mExample\u001b[0;0m \u001b[0;44;31mExample\u001b[0;0m \u001b[0;44;32mExample\u001b[0;0m \u001b[0;44;33mExample\u001b[0;0m \u001b[0;44;34mExample\u001b[0;0m \u001b[0;44;35mExample\u001b[0;0m \u001b[0;44;36mExample\u001b[0;0m \u001b[0;44;37mExample\u001b[0;0m
\u001b[0;45;30mExample\u001b[0;0m \u001b[0;45;31mExample\u001b[0;0m \u001b[0;45;32mExample\u001b[0;0m \u001b[0;45;33mExample\u001b[0;0m \u001b[0;45;34mExample\u001b[0;0m \u001b[0;45;35mExample\u001b[0;0m \u001b[0;45;36mExample\u001b[0;0m \u001b[0;45;37mExample\u001b[0;0m
\u001b[0;46;30mExample\u001b[0;0m \u001b[0;46;31mExample\u001b[0;0m \u001b[0;46;32mExample\u001b[0;0m \u001b[0;46;33mExample\u001b[0;0m \u001b[0;46;34mExample\u001b[0;0m \u001b[0;46;35mExample\u001b[0;0m \u001b[0;46;36mExample\u001b[0;0m \u001b[0;46;37mExample\u001b[0;0m
\u001b[0;47;30mExample\u001b[0;0m \u001b[0;47;31mExample\u001b[0;0m \u001b[0;47;32mExample\u001b[0;0m \u001b[0;47;33mExample\u001b[0;0m \u001b[0;47;34mExample\u001b[0;0m \u001b[0;47;35mExample\u001b[0;0m \u001b[0;47;36mExample\u001b[0;0m \u001b[0;47;37mExample\u001b[0;0m

Bold

\u001b[1;30mExample\u001b[0;0m \u001b[1;31mExample\u001b[0;0m \u001b[1;32mExample\u001b[0;0m \u001b[1;33mExample\u001b[0;0m \u001b[1;34mExample\u001b[0;0m \u001b[1;35mExample\u001b[0;0m \u001b[1;36mExample\u001b[0;0m \u001b[1;37mExample\u001b[0;0m

Underlined

\u001b[4;30mExample\u001b[0;0m \u001b[4;31mExample\u001b[0;0m \u001b[4;32mExample\u001b[0;0m \u001b[4;33mExample\u001b[0;0m \u001b[4;34mExample\u001b[0;0m \u001b[4;35mExample\u001b[0;0m \u001b[4;36mExample\u001b[0;0m \u001b[4;37mExample\u001b[0;0m
@aiko-chan-ai

Copy link
Copy Markdown

https://www.npmjs.com/package/discord-bettermarkdown
i have created a simple library for nodejs to use it :3

@revelcw

revelcw commented Mar 27, 2023

Copy link
Copy Markdown

https://www.npmjs.com/package/discord-bettermarkdown i have created a simple library for nodejs to use it :3

Not the string proto 😭😭😭

@PauliusV0

Copy link
Copy Markdown

Completely doesn't work
image
image

@kkrypt0nn

kkrypt0nn commented May 6, 2023

Copy link
Copy Markdown
Author

Completely doesn't work

Can confirm it completely works - that's what happens when you use BetterDiscord, or similar, with plugins that alter the default behaviour of code blocks or syntax highlighting 🙃
image
image

ghost commented Jul 13, 2023

Copy link
Copy Markdown

Thanks to Clyde for pointing that out, you can clear any effects (bold/underline, fg color, bg color) by using 0.

@mgundle302

Copy link
Copy Markdown

The background of "red" is more of an orange color. How do we get an actual "Red" color or a "Bright Green" color in the background?

@n01-op

n01-op commented Aug 15, 2023

Copy link
Copy Markdown

what are the colours in the #ffffff format?
want to create roles on discord with the same colours

@luigge

luigge commented Nov 3, 2023

Copy link
Copy Markdown

apparently you can also use the escape code number 5 which is supposed to make the text blink and uncer certain circunstances when you hover the mouse over the text it changes the background, I haven't figured out exactly how it works also you can input multiple codes into one for example

�[0;32;40m where 0 is the code to clear the format, then comes the text color then the background color all separated by semicolons

@imtumbleweed

imtumbleweed commented May 25, 2024

Copy link
Copy Markdown

i hope discord devs add support for color in regular chat without having to use code blocks. thanks for this page, it was used as a reference in this article about using color in text on discord which also has a link to the youtube tutorial that has 58K views! clearly, there is so much demand for this feature, discord should just add it out of the box.

@GAMINGCHATS

GAMINGCHATS commented Jul 21, 2024

Copy link
Copy Markdown

I noticed in the 2nd example

\u001b[1;40;32mThat's some cool formatted text right?\u001b[0m

That the order doesn't matter at all.

@prehistoriccraftman

Copy link
Copy Markdown

what you called "yellow" is called ocher or gold, in a normal world. Yellow is yellow, like a mature lemon.

@kkrypt0nn

Copy link
Copy Markdown
Author

what you called "yellow" is called ocher or gold, in a normal world. Yellow is yellow, like a mature lemon.

image

https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

The other colors have custom names because they're not really following ANSI.

@NathanSnail

Copy link
Copy Markdown

In case someone wants the hex codes
foreground 30: #4e5058
foreground 31: #dc322f
foreground 32: #859900
foreground 33: #b58900
foreground 34: #268bd2
foreground 35: #d33682
foreground 36: #2aa198
foreground 37: #ffffff

background 40: #002b36
background 41: #cb4b16
background 42: #586e75
background 43: #657b83
background 44: #839496
background 45: #6c71c4
background 46: #93a1a1
background 47: #fdf6e3

@YannickTholomier

Copy link
Copy Markdown

Date & time:
Any idea how i can post <t:1733099740:D> into a ansi without losting the format?

@kkrypt0nn

Copy link
Copy Markdown
Author

Date & time: Any idea how i can post <t:1733099740:D> into a ansi without losting the format?

Not possible, you can't put other markdown/message formatting within code blocks.

@mwpowellhtx

Copy link
Copy Markdown

This is like the discord markdown bible for colorizing and styling text. Fantastic!

@AstraDawn

Copy link
Copy Markdown

Shame it doesn't support 24 bit color

@simonLeary42

Copy link
Copy Markdown

python script to convert arbitrary ANSI escape sequences into the few colors that discord supports: https://github.com/simonLeary42/daad

@bunny4200

Copy link
Copy Markdown

@WlodekM @Delitel-WEB Read carefully:

\u001b is the unicode escape for ESCAPE/ESC, meant to be used in the source of your bot (see http://www.unicode-symbol.com/u/001B.html). If you wish to send colored text without using your bot you need to copy the character from the website.

Copy here: �[0;0m image

So what would the raw message be then? I am not understanding.

@hwprinz

hwprinz commented May 5, 2026

Copy link
Copy Markdown

@kkrypt0nn
any idea, seems Discord has just changed 'interpretation' of the colors

image image

@kkrypt0nn

Copy link
Copy Markdown
Author

They finally decided to follow the colors of the ANSI standard and not have some weird colors for the backgrounds.

I'll update the images and examples as soon as I can 👍

@mwpowellhtx

mwpowellhtx commented May 5, 2026

Copy link
Copy Markdown

They finally decided to follow the colors of the ANSI standard and not have some weird colors for the backgrounds.

Really, so I gather that is a change from the current strategies then?

I'll update the images and examples as soon as I can 👍

So, efforts around a AnsiTextMessageBuilder are obsolete? When is that changing? And to what? i.e. for brevity (obviously there are actual ANSI values being injected there, TextColorWhite for instance defined as 37:

public enum AnsiBackgroundColor
{
    BackgroundColorDarkTeal,
    BackgroundColorOrange,
    BackgroundColorDarkGray,
    BackgroundColorWarmGray,
    BackgroundColorGray,
    BackgroundColorPurple,
    BackgroundColorLightGray,
    BackgroundColorWhite
}

public enum AnsiTextColor
{
    TextColorGray,
    TextColorRed,
    TextColorGreen,
    TextColorYellow,
    TextColorBlue,
    TextColorMagenta,
    TextColorCyan,
    TextColorWhite
}

public enum AnsiFormat
{
    FormatNormal,
    FormatBold,
    FormatUnderline
}

And:

class AnsiTextMessageBuilder
{
    public AnsiTextMessageBuilder Append(string text) ... ;

    public AnsiTextMessageBuilder AppendFormatted(string text, AnsiFormat format = FormatNormal, AnsiTextColor? textColor = null, AnsiBackgroundColor? backgroundColor = null) ... ;

    public AnsiTextMessageBuilder InsertFormatted(int index, string text, AnsiFormat format = FormatNormal, AnsiTextColor? textColor = null, AnsiBackgroundColor? backgroundColor = null) ... ;

    public AnsiTextMessageBuilder ReplaceFormatted(int index, string text, AnsiFormat format = FormatNormal, AnsiTextColor? textColor = null, AnsiBackgroundColor? backgroundColor = null) ... ;

    public AnsiTextMessageBuilder Clear() ... ;

    public override string ToString() ... ;
}

Thoughts? 🧠 💡

@TinyVirtual

Copy link
Copy Markdown

Discord ANSI Syntax TrueColor Support $${\color{#ffff00}\textsf{[Experimental]}}$$

I know this thread might not be active anymore, but discord is experimenting true color ansi syntax, and i aparently am patient 0, as there is no documentation about "Discord Ansi TrueColor Syntax" or anything related

\u001B[38;2;255;0;0mR\u001B[0m\u001B[38;2;255;37;0ma\u001B[0m\u001B[38;2;255;75;0mi\u001B[0m\u001B[38;2;255;112;0mn\u001B[0m\u001B[38;2;255;149;0mb\u001B[0m\u001B[38;2;255;187;0mo\u001B[0m\u001B[38;2;255;224;0mw\u001B[0m\u001B[38;2;249;255;0m \u001B[0m\u001B[38;2;211;255;0mt\u001B[0m\u001B[38;2;174;255;0me\u001B[0m\u001B[38;2;137;255;0ms\u001B[0m\u001B[38;2;100;255;0mt\u001B[0m\u001B[38;2;62;255;0m:\u001B[0m\u001B[38;2;25;255;0m \u001B[0m\u001B[38;2;0;255;12mL\u001B[0m\u001B[38;2;0;255;50mo\u001B[0m\u001B[38;2;0;255;87mr\u001B[0m\u001B[38;2;0;255;124me\u001B[0m\u001B[38;2;0;255;162mm\u001B[0m\u001B[38;2;0;255;199m \u001B[0m\u001B[38;2;0;255;236mI\u001B[0m\u001B[38;2;0;236;255mp\u001B[0m\u001B[38;2;0;199;255ms\u001B[0m\u001B[38;2;0;162;255mu\u001B[0m\u001B[38;2;0;124;255mn\u001B[0m\u001B[38;2;0;87;255m \u001B[0m\u001B[38;2;0;50;255mD\u001B[0m\u001B[38;2;0;12;255mo\u001B[0m\u001B[38;2;25;0;255ml\u001B[0m\u001B[38;2;62;0;255mo\u001B[0m\u001B[38;2;100;0;255mr\u001B[0m\u001B[38;2;137;0;255m \u001B[0m\u001B[38;2;174;0;255mS\u001B[0m\u001B[38;2;211;0;255mi\u001B[0m\u001B[38;2;249;0;255mt\u001B[0m\u001B[38;2;255;0;224m \u001B[0m\u001B[38;2;255;0;187mA\u001B[0m\u001B[38;2;255;0;149mm\u001B[0m\u001B[38;2;255;0;112me\u001B[0m\u001B[38;2;255;0;75mt\u001B[0m\u001B[38;2;255;0;37m.\u001B[0m

this is the code to put in the codeblock, and remember to replace all \u001B with the escape character

159943 159927 it works currently on both chromium for mobile and desktop, i haven't tested firefox or safari

also this doesn't work for everyone, i still haven't found any other person with that experiment too, and according to my searches, i am probably patient 0

@kkrypt0nn

Copy link
Copy Markdown
Author

It's mainly that people don't use it.

I will see how to edit the Gist accordingly

@mwpowellhtx

Copy link
Copy Markdown

I know this thread might not be active anymore...

It's active enough. This is interesting and I might turn around and figure on adopting a similar approach somehow.

It's mainly that people don't use it.

Then call me a mainly person then. I even cooked up a CSharp "builder" to encapsulate it. but you're not incorrect, I do not see many calls for it by a and large.

@hwprinz

hwprinz commented Jul 11, 2026

Copy link
Copy Markdown

@TinyVirtual
unfortunately not working for me ( Edge & Firefox)
image
(only tried the red 255;0;0 for a test) whereby all the 'older' sequences work

@hwprinz

hwprinz commented Jul 11, 2026

Copy link
Copy Markdown

like
image

@mwpowellhtx

Copy link
Copy Markdown

As an "experimental" thing, does it require a bot be added perhaps? 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment