Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Bot Viewer Detector

Scans your Twitch chat's current viewer list and flags accounts that look like follow/view-bots, so you can review and block them manually. Nothing is banned automatically.

  • / — dashboard: sorted table of flagged accounts with reasons. Once connected, this is also the landing page.
  • /json — same data as JSON.
  • !botcheck — chat command that replies with just the count, e.g. "🤖 4 likely bot viewers out of 212 in chat right now."

What changed from the env-var version

You no longer set TWITCH_BROADCASTER_LOGIN or TWITCH_MOD_OAUTH_TOKEN by hand. Instead, visiting /connect and authorizing on Twitch captures your login, ID, and a refreshable moderator:read:chatters token automatically — same OAuth pattern GuildScribe already uses (/connect → Twitch → /callback), stored in this project's own SQLite database. The token also now refreshes itself instead of expiring every ~4 hours.

How detection works

Each chatter is scored on:

  • Account age (younger = more suspicious)
  • Default/missing profile picture
  • Username shape (word+digits, long random strings — common bot-generator patterns)

Known legitimate bots (Nightbot, StreamElements, etc. — see botDetection.ts) are always excluded. This is heuristic, not certain — glance at a flagged account before blocking it.

Setup on Val Town

  1. Create a new Val Town project and upload main.ts, twitch.ts, db.ts, and botDetection.ts. Set main.ts as the HTTP val entrypoint.

  2. Add these four environment variables (account-level Environment Variables page):

    KeyValue
    TWITCH_CLIENT_IDyour app's Client ID — reuse GuildScribe's
    TWITCH_CLIENT_SECRETyour app's Client Secret — reuse GuildScribe's
    TWITCH_BOT_IDyour bot account's numeric user id — reuse GuildScribe's
    EVENTSUB_SECRETany random string you make up — doesn't need to match GuildScribe's
  3. Open the val's URL — you'll land on a "Connect my channel" page. Click it, authorize on Twitch, and you're done: broadcaster login, chatters token, and EventSub subscription are all set up automatically in that one step.

  4. In Twitch chat, run /mod guildscribebot (or whichever account owns TWITCH_BOT_ID) if it isn't already modded, so it's allowed to speak.

  5. Type !botcheck in chat — you should get a reply within a few seconds.

  6. Reloading / from then on shows the dashboard directly, no reconnecting needed unless Twitch revokes the authorization.

Known limitations

  • If the stored token ever gets revoked (e.g. you remove the app's access in your Twitch settings), !botcheck and / will say the channel needs to reconnect — just visit /connect again.
  • !botcheck re-scans the whole chatter list on every call, so there's a couple seconds of delay before the reply — that's expected, not a bug.