Automatically send message to chat with PHP?

I have a ‘featured Twitch stream’ section on my site that rotates between a list of user submitted channels every 30 minutes. I’m wondering if it’s possible to automatically send a message from my Twitch account into the featured streamer’s chat that says something like “You are now the featured stream on!”.

Is there is some sort of API function for this?

Hello Swennet,

There is no “API” calls for that, you’ll need to connect via sockets in PHP to the twitch irc chat ( and use the IRC RFC references to send message to the channel.

For instance, you’ll need your oauth token that you’ll send as a PASS command parameter once connected to the server, then send the NICK yourNickname to complete authentication (nickname must be in lower case).

Once it is done, you can JOIN the channel you want to send the message to, and use PRIVMSG to send the desired message.

For more informations, please read Github Twitch page about API and IRC chat.

Best regards,
Hugo R.

1 Like

There is no point to doing this.

Your bot will get automatically banned by the channel moderator Bot.
And then your bot will get banned by Twitch for the sheer number of automated bot bans of your bot.

It is spam and blatant advertising of yourself in other peoples channels (sure it’s fine for opt in channels that are expecting it and thus have modded/whitelisted your bot)

(but yes as @AenoaLabs says, you’ll need a bot or implement a dirty quick IRC join slash and burn script)


Thank you for the info @AenoaLabs, it’s very useful!

I know this feature would be considered spam or advertising by a lot of people, so I was planning to add a checkbox which enables these automatic chat messages. (unticked by default)

The feature would be used primarily to notify the streamer that their channel is being featured on my site, but maybe sending a PM would work better. Is it possible to do that using the same technique? (connecting to IRC and sending a message to the user instead of the room)

Also, what does the channel moderator Bot look for when banning messages/users? Is it posting ‘unauthorized’ links in the chat?

Thank you for your input :slight_smile:

The definition of “unauthorized” varies by chat, bot, broadcaster.

To be honest I wouldn’t bother with such a feature at all. I think there are better ways to promote your site and than auto dropping a message in chat, or getting a featured streamer to talk about it whilst they are featured. It’s interuptty to the stream

The feature is mostly meant to notify the streamer that they’re being featured. The advertising is just a nice bonus. Right now, an email is automatically sent to the featured streamer, but they most likely won’t read that until after the stream. I figured sending it in Twitch would be the best way to notify a streamer about it without forcing them to check their email or my website.

I will just leave it as it is now, and then decide later if they really need to be notified about being featured.

Thanks for the help everyone!

As long as it’s strictly opt-in for the streamer I don’t see anything wrong with it. Maybe you should ask the streamers that are participating in your site if they would like such a notification, if they are the ones that it’s primarily for.

1 Like

With that being said, send the person a whisper vs putting it in the chat
It will still let the streamer know and they have the choice to talk about it

1 Like

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