Hello i've tried to connect to the Twitch IRC Chat so i can try to make a simple chat bot for twitch but im struggling to make it work.
Error im getting: http://puu.sh/j3HwK/173a0388fb.png
and here is the code:
<?php
set_time_limit(0);
ini_set('display_errors', 'on');
function IRCBot()
{
function IRC()
{
$config = array(
'server' => 'irc.twitch.tv',
'port' => 6667,
'channel' => '#spiritboar',
'name' => 'bin4rybot',
'nick' => 'Bin4ryBOT',
'pass' => 'oauth:##########################' //http://twitchapps.com/tmi/
);
echo 'test';
$server = array();
$server['connect'] = fsockopen($config['server'], $config['port']);
if($server['connect'])
{
echo 'test2';
SendData("PASS " . $config['pass'] . "\n\r");
SendData("NICK " . $config['nick'] . "\n\r");
SendData("USER " . $config['nick'] . "\n\r");
SendData("JOIN " . $config['channel'] . "\n\r");
while(!feof($server['connect']))
{
echo 'test3';
}
}
}
function SendData($cmd)
{
global $server;
fwrite($server['connect'], $cmd, strlen($cmd));
echo "[SEND] $cmd <br>";
}
IRC();
}
IRCBot();
?>
So basicly i cant make it connect to the Twitch IRC, Please if someone can help me it would be much appreciated! :)
I know it was asked soo manny years ago, but perhaps can help someone else today:
<?php
set_time_limit(0);
ini_set('display_errors', 'on');
$server = array();
function IRCBot()
{
function IRC()
{
$server global;
$config = array(
'server' => 'ssl://irc.chat.twitch.tv',
'port' => 6697,
'channel' => '#twitch_channel',
'nick' => strtolower('twitch_username'),
'pass' => 'oauth:twitch_oauth_token' //http://twitchapps.com/tmi/
);
$server['connect'] = @fsockopen($config['server'], $config['port']);
if($server['connect'])
{
echo "[<] Starting connection with user: " . $config['nick'];
SendData('CAP REQ :twitch.tv/tags');
SendData('CAP REQ :twitch.tv/commands');
SendData('CAP REQ :twitch.tv/membership');
SendData("PASS " . $config['pass']);
SendData("NICK " . $config['nick']);
SendData("USER " . $config['nick'] . " 1 1 :" . $config['nick']);
SendData("JOIN " . $config['channel']);
while(!feof($server['connect']))
{
$server['READ_BUFFER'] = fgets($server['connect'], 1024);
echo "[>] " . $server['READ_BUFFER'];
flush();
}
}
}
function SendData($cmd)
{
global $server;
@fwrite($server['connect'], $cmd . "\r\n");
echo "[<] $cmd \r\n";
}
IRC();
}
IRCBot();
The most important thing to notice beyond the format of the commands send to twitch, it's that the SendData function does not send strlen on the fwrite function and the "\r\n" append to command string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With