Skip to content
Entity Info byteCount

$byteCount

The $byteCount[] function calculates the number of bytes of a given text. Useful for checking Discord message size limits or evaluating data size.

Syntax

$byteCount[text]

Parameters

Parameter Description
text The text of which you want to know the size in bytes.

Return value

  • Type: String (number)
  • The number of bytes that the text represents.

Behavior

  • Counts UTF-8 bytes, not characters (a Unicode character can be multiple bytes). Probe: Hello World = 11, Héllö Wörld = 14, Hello 👋 = 10.
  • Exactly one argument is required; an empty text returns 0.
  • ASCII characters count as 1 byte, accented letters as 2, most CJK characters as 3 and emojis as 4.
  • Useful for validating data before storage or sending.

Examples

Checking before sending

$var[size;$byteCount[$message]]
$if[$var[size]>2000]
  $sendMessage[⚠️ Message too long ($var[size] bytes). Discord limit: 2000 characters.]
$else
  $sendMessage[$message]
$endif

Checking stored data

$var[data;$getVar[userData]]
$var[size;$byteCount[$var[data]]]

$title[📦 User Data]
$description[
**Size:** $var[size] bytes ($calculate[$var[size]/1024] KB)
**Number of characters:** $charCount[$var[data]]
]

Size comparison

$var[ascii;$byteCount[Hello World]]
$var[unicode;$byteCount[Héllö Wörld]]
$var[emoji;$byteCount[Hello 👋]]

ASCII: $var[ascii] bytes
Unicode (accents): $var[unicode] bytes
With emoji: $var[emoji] bytes

Notes

  • $byteCount differs from $charCount: $charCount counts characters, $byteCount counts bytes.
  • With pure ASCII text, both values are identical.
  • Discord limits messages to 2000 characters (not bytes), but this function remains useful for storage calculations.

Try it

Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.