Builders

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

Formatters

Formatters are a set of utility functions that format input strings into the given format.

Basic Markdown

The Formatters provide functions to format strings into all the different Markdown styles supported by Discord.

const { bold, italic, strikethrough, underscore, spoiler, quote, blockQuote } = require('discord.js');
const string = 'Hello!';

const boldString = bold(string);
const italicString = italic(string);
const strikethroughString = strikethrough(string);
const underscoreString = underscore(string);
const spoilerString = spoiler(string);
const quoteString = quote(string);
const blockquoteString = blockQuote(string);
1
2
3
4
5
6
7
8
9
10

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

const { hyperlink, hideLinkEmbed } = require('discord.js');
const url = 'https://discord.js.org/';

const link = hyperlink('discord.js', url);
const hiddenEmbed = hideLinkEmbed(url);
1
2
3
4
5

Code 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.

const { inlineCode, codeBlock } = require('discord.js');
const jsString = 'const value = true;';

const inline = inlineCode(jsString);
const codeblock = codeBlock(jsString);
const highlighted = codeBlock('js', jsString);
1
2
3
4
5
6

Timestamps

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

const { time } = require('discord.js');
const date = new Date();

const timeString = time(date);
const relative = time(date, 'R');
1
2
3
4
5

Mentions

The Formatters also contain various methods to format Snowflakes into mentions.

const { userMention, memberNicknameMention, channelMention, roleMention } = require('discord.js');
const id = '123456789012345678';

const user = userMention(id);
const nickname = memberNicknameMention(id);
const channel = channelMention(id);
const role = roleMention(id);
1
2
3
4
5
6
7