Nightbot Counter

Asked Apr 28, 2025·1 reply·Last activity 1 year ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

One Man's attempt at making a scoreboard for beer hockey

I managed to create a Counter which can be used for any number of things. I am using it as a scoreboard for beer league hockey I play. (Technically I am using three different counters. One for a score for each team, and 1 for the period of the game) But this could be used as a Bad Joke counter, or a Death Counter, or any other things. This counter is set and updated Via Nightbot commands. And then displayed within the Stream on a local HTML page.

You can create any number of Keys (Counters you want) with this API.

The Counter Site
https://counterapi.dev/ API Main Website
https://counterapi.dev/api/endpoints.html API EndPoints

API URL

|name|required|description|
|---|---|---|
|name|yes|Namespace for the counter|
|key|yes|Counter name|
https://api.counterapi.dev/v1/**Name**/**Key**/ -Get Value of Key //NOTE There is a 60 second cache on Get Values
https://api.counterapi.dev/v1/**Name**/**Key**/UP -Increment Value of Key by 1
https://api.counterapi.dev/v1/**Name**/**Key**/DOWN -Decrease Value of Key by 1
https://api.counterapi.dev/v1/**Name**/**Key**/UP -Increment Value of Key by 1
https://api.counterapi.dev/v1/**Name**/**Key**/set?count=1 -Set Value of Key to Number specified (Can not be Zero)

//To set a Count to Zero. You can set the Key to ONE. Then Decrease the value of the key

Nightbot Commands

The Following is NightBot code. You add this to a "Nightbot" message, and running it will update the count.

Player 1 has Scored/Leveled/Died. The Current count is $(eval a=$(urlfetch json https://api.counterapi.dev/v1/**Name**/**Key**/); a.count)

This code can show you current count of the Count.

1 reply

The Current Value of the Count is $(eval a=$(urlfetch json https://api.counterapi.dev/v1/**Name**/**Key**/); a.count)

This Code can be used to set a Count to Zero
Reset Count $(eval a=$(urlfetch json https://api.counterapi.dev/v1/**Name**/**Key**/set?count=1);) $(eval b=$(urlfetch json https://api.counterapi.dev/v1/**Name**/**Key**/down); )

HTML CODE
Below is a Simple HTML Page that will display the Value of the Count. You can add this an Overlay on your stream.

<p class="count" id="count"></p>
<script>
async function pollAPI() {
const endpoint = 'https://api.counterapi.dev/v1/**Name**/**Key**/';
try {
const response = await fetch(endpoint);
const data = await response.json();
console.log('API Response:', data); // Log the raw response for debugging
// Update the count using the correct key
if (data && typeof data.count !== 'undefined') {
document.getElementById('count').textContent = data.count;
} else {
document.getElementById('count').textContent = 'No count found in response.';
console.error('Unexpected response format:', data);
}
} catch (error) {
document.getElementById('count').textContent = 'Error!';
console.error('Error polling API:', error);
}
}
// Poll the API every 5 seconds
setInterval(pollAPI, 5000);
// Fetch the count immediately when the page loads
pollAPI();
</script>