Section titled FormattersFormatters

discord.js provides the @discordjs/formatters package which contains a variety of utilities you can use when writing your Discord bot.

Section titled Basic MarkdownBasic Markdown

These functions format strings into all the different markdown styles supported by Discord.


_10
import { bold, italic, strikethrough, underscore, spoiler, quote, blockQuote } from 'discord.js';
_10
_10
const string = 'Hello!';
_10
const boldString = bold(string);
_10
const italicString = italic(string);
_10
const strikethroughString = strikethrough(string);
_10
const underscoreString = underscore(string);
_10
const spoilerString = spoiler(string);
_10
const quoteString = quote(string);
_10
const blockquoteString = blockQuote(string);

There are also two functions to format hyperlinks. hyperlink() will format the URL into a masked markdown link, and hideLinkEmbed() will wrap the URL in <>, preventing it from embedding.


_10
import { hyperlink, hideLinkEmbed } from 'discord.js';
_10
_10
const url = 'https://discord.js.org/';
_10
const link = hyperlink('discord.js', url);
_10
const hiddenEmbed = hideLinkEmbed(url);

Section titled Code blocksCode blocks

You can use inlineCode() and codeBlock() to turn a string into an inline code block or a regular code block with or without syntax highlighting.


_10
import { inlineCode, codeBlock } from 'discord.js';
_10
_10
const jsString = 'const value = true;';
_10
const inline = inlineCode(jsString);
_10
const codeblock = codeBlock(jsString);
_10
const highlighted = codeBlock('js', jsString);

Section titled TimestampsTimestamps

With time(), you can format Unix timestamps and dates into a Discord time string.


_10
import { time, TimestampStyles } from 'discord.js';
_10
_10
const date = new Date();
_10
const timeString = time(date);
_10
const relative = time(date, TimestampStyles.RelativeTime);

Section titled MentionsMentions

userMention(), channelMention(), and roleMention() all exist to format Snowflakes into mentions.


_10
import { channelMention, roleMention, userMention } from 'discord.js';
_10
_10
const id = '123456789012345678';
_10
const channel = channelMention(id);
_10
const role = roleMention(id);
_10
const user = userMention(id);