How to handle subscription events in JavaScript Twitch bot

I’m building a JavaScript bot for Twitch and need help with detecting when users subscribe to the channel. I want my bot to automatically thank new subscribers.

I tried using the USERNOTICE event but I’m confused about the implementation:

botClient.on("message", () => {
    botClient.say(settings.channel, '/usernotice response');
});

Is calling /usernotice the right approach for responding to subscription events?

I also found some older code examples that use specific subscription handlers:

twitchBot.onSubscribe((channelName, username) => {
    twitchBot.say(channelName, `Welcome @${username}, thanks for the sub!`);
});

twitchBot.onResubscribe((channelName, username, subData) => {
    twitchBot.say(channelName, `@${username} has been subscribed for ${subData.totalMonths} months!`);
});

twitchBot.onGiftSub((channelName, recipient, giftData) => {
    twitchBot.say(channelName, `${giftData.gifterName} just gifted a sub to ${recipient}!`);
});

But when I try these methods, I get “TypeError: botClient.onSubscribe is not a function”.

I also attempted this approach:

twitchBot.on('subscribe', (channelName, username) => {
    twitchBot.say(channelName, `@${username} thanks for subscribing!`);
});

What’s the correct way to handle subscription events in modern Twitch bot development? Testing this functionality is challenging since I can’t easily simulate subscription events.

Honestly, just use tmi.js for chat and run a separate Express server for EventSub webhooks. Takes maybe 20 minutes to set up - register your webhook URL with Twitch’s API, handle the verification challenge, then listen for subscription posts. When the webhook hits, use your existing tmi client to send the thank you message. Way less complicated than people make it sound.

You’re mixing old IRC methods with modern Twitch APIs. That’s like trying to run Instagram on a flip phone.

I’ve built several Twitch bots and learned this the hard way. Twitch killed most IRC subscription events years ago. You need EventSub webhooks for sub detection and IRC for chat responses.

EventSub setup is a nightmare though. You need webhook servers, auth flows, event subscriptions, and constant maintenance when Twitch changes stuff.

I solved this using Latenode instead. It handles all the EventSub mess for you. Connect your Twitch account, set up a subscription trigger, and you’re done - clean webhook data whenever someone subs.

Then use Latenode to format and send the thank you message back to chat. No more wrestling with auth tokens or webhook verification.

Moved three different bots to this setup and saved probably 40 hours of debugging EventSub quirks. Testing’s simple since you can manually trigger workflows.

Those onSubscribe methods you found are from dead libraries. Don’t waste time trying to fix them.

You’re hitting this because those onSubscribe methods are from dead libraries that nobody maintains anymore. You need Twitch’s EventSub system now - keep your IRC connection but add a webhook endpoint to catch subscription notifications. Set up the webhook, authenticate with EventSub API, and subscribe to the channel.subscribe event. When someone subs, Twitch sends a POST request to your webhook with the data. I ran into the same mess migrating from old libraries - ngrok saved my sanity for local testing. Here’s the thing: sub events don’t come through chat anymore, they hit your webhook as HTTP requests. So you’ll handle EventSub webhooks for detecting subs and keep IRC for sending thank you messages.

That error means you’re using a library that doesn’t support those methods. I hit the same wall with tmi.js - it’s great for chat but has zero support for subscription events. Subscriptions now run through EventSub as server-to-server events, while chat still uses IRC. You need both connections running at once. I ended up dealing with two separate auth processes: one for EventSub webhooks, another for IRC chat. The webhook gets subscription data as JSON, I parse it for the username and sub details, then fire off the thank you message through IRC. Setting up webhook verification was a pain - Twitch wants specific response headers and tight timing.

Your code won’t work because you’re trying to listen for subs through IRC chat - that hasn’t worked since 2021. Twitch killed that when they moved everything to EventSub, which broke tons of older tutorials and libraries. I hit the same wall updating my bot last year. You need two things now: EventSub webhooks to catch subscription events, and your IRC connection to send the thank you messages. Can’t detect subs through chat anymore, period. For EventSub, you’ll create webhook endpoints that handle Twitch’s subscription payloads. The webhook gets JSON data with subscriber info, then you use that to trigger your thank you messages via IRC. The verification process is annoying but you have to do it. For testing, grab Twitch CLI - it’s great for simulating events locally. Install it and use the event trigger commands to send test payloads to your webhook. Way better than bugging friends to subscribe for testing. That /usernotice thing you tried is completely wrong here. It’s for different chat events, not subscription detection.

This depends on your library. Most modern JavaScript Twitch bot libraries handle subscriptions through EventSub webhooks, not IRC messages - Twitch has deprecated most IRC-based subscription notifications. If you’re using tmi.js, it doesn’t natively support subscription events, so you’ll need to utilize the EventSub API separately. The USERNOTICE method only applies to certain chat events, not subscriptions. For testing purposes, consider using Twitch CLI to simulate webhooks locally by executing twitch event trigger subscribe, which can help you test your handlers without requiring actual subscriptions. This was a significant time-saver while developing my bot. Although EventSub requires more initial setup, it effectively detects subscriptions and involves registering webhook endpoints and managing the verification process.