velho
Examples

Chat Command Bot

Create a resilient chat bot that joins a channel, listens for commands, and responds with live data fetched from Helix.

Environment

TWITCH_CHANNEL_LOGIN, TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET, TWITCH_CHAT_USERNAME, TWITCH_CHAT_TOKEN — the setup CLI writes them to .env for you.

Get started

  1. Install project dependencies with bun install.
  2. Run bunx velho-setup to walk through the interactive OAuth helper, or manually create a .env file with the required credentials listed above.
  3. Give your bot account chat permissions by visiting the generated authorization URL and completing consent.
  4. Start the bot with bun run examples/CHAT_COMMAND_BOT.ts. The script validates your environment variables and connects to chat.
  5. Type commands such as !uptime, !title, or !help from the channel to see the bot respond.

What you can do

  • Listen for chat messages and filter them by channel or user roles.
  • Fetch uptime and title information via the Helix API and reply instantly in chat.
  • Handle reconnects and error conditions with informative logging for on-call teams.
  • Expand the handleCommand function to support moderation or loyalty workflows.

Operational tips

  • Swap autoJoin for a dynamic list if the bot needs to monitor multiple channels.
  • Persist the broadcaster ID instead of requesting it on every command to minimise Helix calls.
  • Combine this bot with EventSub notifications to announce follows, subs, and channel point rewards.

Resources

On this page