Bot to Whisper when followed or subscribed

I have used the below to connect my bot.

This is very new to me and I want the bot to whisper an individual after a follow or a subscription. I’ve spent nearly 2 hours trying to research this but have not been lucky. Maybe I don’t know exactly what to search for. Would anyone be able to assist me in adding code to the below to whisper a user when they follow or subscribe to my channel?

const tmi = require(‘tmi.js’);

const options = {
options: {
debug: true,
},
connection:{
Cluster: ‘aws’
reconnect: true,
},
identity:{
username: ‘username’,
password:‘oauth:*****’,
},
channels:{‘mychannel’],
};

const client = new tmi.clent(options);

client.connect();

client.on(‘connected’, (addres, port) => {
client.action(mychannel’,‘Bot now connected’);
});

client.on(‘chat’, (channel, user, message, self) => {
if (message === ‘!info’) {
client.action(‘mychannel’,‘Info text placed here’);
}
});

  1. Don’t do this, it’s an unsolicited Whisper.
  2. Whispers will fail when you are sending a bot without being a “known bot”
  1. What is the actual error message you are getting?

I see you are using TMI.js

Cluster: ‘aws’

Is no longer required. And based on an old example.

There is no whisper code in your code, I don’t see anything you have tried, this looks like the example code from the tmi.js help/starter Docs

I can lead you to the answer but I won’t give you the answer

If you really wanna whisper new followers (which I don’t recommend), best method would be to use webhooks to recieve new follows

https://dev.twitch.tv/docs/api/webhooks-guide/

And you’ll need adequate protection in place to make sure you don’t try to whisper the same person twice in a defined time frame, some people like to unfollow/refollow to see their name in your follow notifier.

Twitch IRC usernotice covers subscriptions

And whispers are just a PRIVMSG .w target

Thanks for the quick reply Barry.

So you don’t believe I should whisper new followers or subscribers/re-subs? I just thought it would be nice and more “personal” if you will rather than sending a chat message. Instead of a whisper, what about sending a message in chat saying thanks for the follow/subscription etc?

I’m not receiving any errors at the moment. Everything is working fine. I’ve set up quite a few chat messages (!info etc.) but I just pasted the basic code I used. I have not added any “whisper code” as I didn’t have luck with my research.

I would be okay with sending a chat message instead but I wasn’t able to find the command line to look out for the new follower/sub/re-sub action. Any other direction or assistance would be greatly appreciated.

Thank you.

Generally speaking, it’s an unwritten rule that a IRC/Chat bot should initiate a conversation, it should only reply and when it replies it replies in the same medium. (So PRIVMSG reply with PRIVMSG whisper reply with whisper)

You are using TMI.js? Your example paste above looks like the TMI.js library

New followers are not “easy” to detect, you’d need your bot to make constant API requests (once per minute and then spam the chat as new followers clear thru the API cache), or use a Web Server to receive follower webhooks in real time which then tells the bot to send a message to chat.

As I noted you can hook onto the USERNOTICE in the docs I already linked.

But if you are using TMI.js you’d need to refer to the TMI.js docs for how their library presents the events for usage.

Thanks again Barry. I’ll post again if I have any further questions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.