Replace
Text replacement, useful in conjunction with other nested counters for comprehensive text modification.
The Replace counter takes a piece of text and swaps parts of it for something else. It is built for cleaning up or rewording what another counter returns, so all of its fields take nested counters.
Availability: every bot type. It makes no network requests, so it needs no API key and no environment variable when you self-host.

Options
Input text
The text the replacements are applied to.
One value only. Takes a nested counter.
Search for
The piece of text to look for.
Plain text only, no regular expressions. Takes a nested counter.
Replace with
What each match becomes.
Takes a nested counter.
Search for and Replace with live together on a replacement card. Use Add replacement to add another card and Remove replacement to delete one. There is no limit on the number of cards.
What it returns
The Input text with every replacement card applied, as text. With no Input text the result is empty text.
The cards run in order, each on the result of the one before it, so card 2 can match text card 1 has just produced.
Matching is literal and case-sensitive, and every occurrence is replaced, not just the first. Searching for
oninOnlinematches nothing, because the text starts with a capitalO.Regular expressions are not supported.
Formatting
A Replace result is text, and the bot only formats numbers, so Use compact notation, Override default locale and Override default digits have no effect on it, nor on any number produced inside it.
When the cleaned-up value is a number and you want it formatted, wrap the Replace counter in a Number counter and put the format settings there, because the bot reads the formatting from the outermost counter only. See Formatting counters.
Refresh and caching
Replace caches nothing. The bot works it out again on every channel update, every 10 minutes on the public bot and every 5 minutes on the other bot types. Anything nested inside it keeps its own refresh behaviour, so an HTTP counter in Input text still refetches on its own Lifetime (in seconds). See How counters update.
Examples
An API returns a figure with a decimal comma, such as 1234,56. Number cannot read that, so fix the separator first.
Add an HTTP counter pointed at the endpoint and set its Data path so it returns just the figure.
Add a Replace counter and nest the HTTP counter in Input text.
Press Add replacement once and fill the card: Search for
,and Replace with., which turns1234,56into1234.56.Wrap the whole Replace counter in a Number counter so the value becomes a real number and Format settings apply to it.

Turn a bare number into something friendlier.
Input text: a nested Members counter with Filter by status set to Online + Idle + DND.
Search for:
1, Replace with:one.
Every occurrence is replaced, so 21 becomes 2one.
Errors
Replace has no errors of its own. What can still go wrong:
The channel shows ERROR!
A counter nested in Input text, Search for or Replace with failed, so the whole template failed. Open the channel in the dashboard and read the error to find the counter at fault.
The result for the channel name is less than 2 characters long.
A voice or category channel name needs at least 2 characters, and an empty Input text is the usual reason. Fill Input text, or add text around the counter in the template.
Nothing changes in the channel
A card is skipped because Search for or Replace with is empty, or the search term does not match because of capitalisation. Fill both fields on every card and check the capitalisation.
If it still fails, Troubleshooting covers the common causes, and you can ask on the support server.
Last updated