What is @discordjs/formatters?
@discordjs/formatters is a utility package designed to help format messages and other content for Discord bots. It provides a set of functions to easily format text in a way that is compatible with Discord's markdown and other formatting features.
What are @discordjs/formatters's main functionalities?
Code Block Formatting
This feature allows you to format text as a code block in Discord. The `codeBlock` function takes two arguments: the language for syntax highlighting and the code itself.
const { codeBlock } = require('@discordjs/formatters');
const formattedCode = codeBlock('js', 'const x = 10;');
console.log(formattedCode);
Inline Code Formatting
This feature allows you to format text as inline code in Discord. The `inlineCode` function takes a single argument: the code to be formatted.
const { inlineCode } = require('@discordjs/formatters');
const formattedInlineCode = inlineCode('const x = 10;');
console.log(formattedInlineCode);
Quote Formatting
This feature allows you to format text as a quote in Discord. The `quote` function takes a single argument: the text to be quoted.
const { quote } = require('@discordjs/formatters');
const formattedQuote = quote('This is a quoted text.');
console.log(formattedQuote);
Bold Text Formatting
This feature allows you to format text as bold in Discord. The `bold` function takes a single argument: the text to be formatted in bold.
const { bold } = require('@discordjs/formatters');
const formattedBoldText = bold('This is bold text.');
console.log(formattedBoldText);
Italic Text Formatting
This feature allows you to format text as italic in Discord. The `italic` function takes a single argument: the text to be formatted in italic.
const { italic } = require('@discordjs/formatters');
const formattedItalicText = italic('This is italic text.');
console.log(formattedItalicText);
Other packages similar to @discordjs/formatters
discord.js
discord.js is a powerful library for interacting with the Discord API. While it is more comprehensive and includes features for creating and managing bots, it also includes some basic formatting utilities. However, it is not as specialized in formatting as @discordjs/formatters.
discord-markdown
discord-markdown is a package that parses and renders Discord-flavored markdown. It is useful for converting markdown to HTML or other formats, but it does not provide the same level of utility functions for formatting text directly as @discordjs/formatters.
markdown-it
markdown-it is a markdown parser that can be extended with plugins to support various markdown features, including those used by Discord. While it is highly customizable and powerful, it is not specifically tailored for Discord's formatting needs like @discordjs/formatters.
About
@discordjs/formatters
set of functions to format strings for Discord.
Installation
Node.js 16.9.0 or newer is required.
npm install @discordjs/formatters
yarn add @discordjs/formatters
pnpm add @discordjs/formatters
Example usage
import { codeBlock } from '@discordjs/formatters';
const formattedCode = codeBlock('hello world!');
console.log(formattedCode);
Links
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation.
See the contribution guide if you'd like to submit a PR.
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official discord.js Server.