discord-widgets

CustomString

The CustomString class is the basis of most fields found inside of discord-widgets.

Prop

Type

Usage

Take a .topWidget surface for example. You can implement the CustomString very simply:

import { , ,  } from "discord-widgets";

new ("Display Name")
  .({
    : .,
    : "Test Widget",
    : "This widget was created with discord-widgets.",
    : new ("number_specific_to_a_user"),
    : "3rd line of subtitle"
  })

Any string-based field on Discord widgets can natively be a number or string. If you just input a string, and not a CustomString, it will just be assigned that string in the initial widget configuration.

That means you cannot change fields that aren't CustomString's after publishing the initial widget configuration, as they are directly embedded inside of the widget configuration, which usually is only designed to be edited once (however it can technically still be edited more than once).

Additionally, widget configurations cannot have strings specific to one user. You must use a CustomString to assign specific users, specific strings, or to change strings after runtime.

Initial Values

discord-widgets will automatically sync an initial value for CustomString's as the library will automatically generate a schema which is a pathway to sync a predefined set of data.

import { , ,  } from "discord-widgets";

new ("Display Name")
  .({
    : .,
    : "Test Widget",
    : "This widget was created with discord-widgets.",
    : new ("number_specific_to_a_user", "39982"),
    : "3rd line of subtitle"
  })

If a CustomString does not have an initial value, you can put it in when you .sync() or .syncAndPublish().

.forceType()

Using .forceType() will force the type to something else. For example, if you want to force a string to a number so Discord's UI will format it nicely for bigger numbers, you can just use the following:

import { , ,  } from "discord-widgets";

new ("Display Name")
  .({
    : .,
    : "Test Widget",
    : "This widget was created with discord-widgets.",
    // This subtitle will show up as "33K" in the Discord UI
    : new ("number_specific_to_a_user", "33333").("number"),
    : "3rd line of subtitle"
  })

On this page