Post: [C#] How to create a simple Twitch Chat Bot [Source Code Included]
10-18-2015, 02:35 AM #1
Sloth
Banned
(adsbygoogle = window.adsbygoogle || []).push({}); Ok so recently I have been working on a project to make a working web based twitch chat bot / chat spammer, I have pretty much finished it except for support on proxies.

I thought it would be cool to let NGU have the ability to make their own as well so here is a tutorial enjoy


Download Link to source provided at the bottom



What we need




  • A C# IDE (I will be using Visual Studio 2015 Pro)
  • A list of twitch users in a text file using this format
    Originally posted by another user
    userName:Oauth
    (I will provide a list with around 6k accounts below please remember these are public so some of them may be banned)
  • A VPN (Twitch bans your IP after sending spam for a long enough time your going to need to change your IP (Ghost VPN is a decent free one)






Step 1 - Creating our Windows Form


So lets create a new windows form project and call it whatever you want.
Next we are going to need to add some controls.


Controls to Add


  • 1 Button
  • 2 Textboxes
  • 2 Labels




So your form should end up like this
You must login or register to view this content.




Step 2 - Writing our Chat Bot code


Now we need to write our chat bot code, for this tutorial I will placing the code in side the forms code file rather than a class file.


First our references
    
using System;
using System.Net.Sockets;
using System.IO;
using System.Windows.Forms;
using System.Threading;



Now our variables


    
//Thread Shutdown Event
static ManualResetEvent _shutdownEvent = new ManualResetEvent(false);
//Boolean to see if thread is running or not
public bool ChatBotRunning = false;
//Declaring the thread
Thread _thread;



Next we need to add our threading functions to start and stop the thread
    
private void StartChatBot()
{
//Loops through the code inside until broken
while (true)
{
try
{
//Reads from a text file containing the user accounts in the same directory as the application.
using (StreamReader TwitchAccountReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "/users.txt"))
{
//Declaring strings
string AccountString;
string[] AccountArray;
//Reads a line from the file
AccountString = TwitchAccountReader.ReadLine();
//Basically it will read each line from the text file until it reaches the end
while ((AccountString = TwitchAccountReader.ReadLine()) != null)
{
//Splits the Line in to 2, [0] is the username, [1] is the Oauth
AccountArray = AccountString.Split(':'Winky Winky;
//Connects to thw Twitch IRC
using (TcpClient TwitchConnection = new TcpClient("irc.twitch.tv", 6667))
{
//This is what we will use to write commands to the IRC
using (StreamWriter TwitchWriter = new StreamWriter(TwitchConnection.GetStream()))
{
//If the shutdown event is signaled the loop will break and the thread will end
if (_shutdownEvent.WaitOne(0))
break;
//Sets the username
TwitchWriter.WriteLine("USER " + AccountArray[0] + "tmi twitch :" + AccountArray[0]);
//Authorises the account using their Oauth
TwitchWriter.WriteLine("PASS oauth:" + AccountArray[1]);
//Set the Nickname
TwitchWriter.WriteLine("NICK " + AccountArray[0]);
//Joins the twitch channel you're going to be spamming
TwitchWriter.WriteLine("JOIN #" + textBox1.Text);
//Sends your Message through the IRC to the Channel you are spamming
TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text + " " + R.Next(9999));
}
}
}
//Checks to see if the Account reader has reached the end of the file
if (TwitchAccountReader.EndOfStream == true)
{
//Resets the reader to the beginning so the spam can restart
TwitchAccountReader.DiscardBufferedData();
TwitchAccountReader.BaseStream.Seek(0, SeekOrigin.Begin);
TwitchAccountReader.BaseStream.Position = 0;
}
}
}
catch (Exception ex)
{
//Shows a message box with the exception error
MessageBox.Show(ex.Message);
}
}
}



Now we need to add the Code for the start button and we should be good to go
    
private void button1_Click(object sender, EventArgs e)
{
//If the Bot is not running
if(ChatBotRunning == false)
{
//Set the Channe Name textbox and Message textbox to disabled
textBox1.Enabled = false;
textBox2.Enabled = false;
//Set our buttons text to 'Stop Chat Bot'
button1.Text = "Stop Chat Bot";
//Set the Boolean StopChatBot to false so it will run
ChatBotRunning = true;
//Start our thread
StartThread();
}
//If the bot is running
else
{
//Set our buttons text to 'Start Chat Bot'
button1.Text = "Start Chat Bot";
//Set the Boolean StopChatBot to true so it will stop
ChatBotRunning = false;
//Set the Channe Name textbox and Message textbox to enabled
textBox1.Enabled = true;
textBox2.Enabled = true;
//Signals the thread shutdown event
StopThread();
}
}



Step 3 - Getting out program ready


Ok So now our code is ready we can test it out we need to find a twitch channel so to do this click on any stream and copy this part of the URL
You must login or register to view this content.


Now we have the channel name we just need to choose a message to send, I will be sending
Originally posted by another user
This stream is 3 spooki 5 me



So our application should look like this
You must login or register to view this content.




Step 4 - Spamming a Channel


Now all you need to do is hit the "Start Chat Bot" Button and watch the magic XD


You must login or register to view this content.



NOTE: These accounts are not verified and some channels require users to verify their email before they can chat so if your spam is not sending that may be the issue.
NOTE: another reason as to why your spam isn't sending could be that you have been IP Banned you can change your IP using a VPN tool such as Ghost VPN.



Downloads


The users.txt file is included inside the debug folder but you may also download it separately below


users.txt Direct Link: You must login or register to view this content.
Project Zip Direct Download: You must login or register to view this content.
Project Zip Virus Scan: You must login or register to view this content.
Last edited by Sloth ; 10-19-2015 at 02:29 AM.

The following 6 users say thank you to Sloth for this useful post:

Devious, Helping-Hand, Kryptus, Mango_Knife, AFG, Winter
10-19-2015, 03:27 AM #11
Sloth
Banned
It could be the channel, sometimes it requires users to have verified emails. Also the chatbot function has been updated so copy and paste it in to the source here it is
    private void StartChatBot()
{
//Loops through the code inside until broken
while (true)
{
try
{
//Reads from a text file containing the user accounts in the same directory as the application.
using (StreamReader TwitchAccountReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "/users.txt"))
{
//Declaring strings
string AccountString;
string[] AccountArray;
//Reads a line from the file
AccountString = TwitchAccountReader.ReadLine();
//Basically it will read each line from the text file until it reaches the end
while ((AccountString = TwitchAccountReader.ReadLine()) != null)
{
//Splits the Line in to 2, [0] is the username, [1] is the Oauth
AccountArray = AccountString.Split(':'Winky Winky;
//Connects to thw Twitch IRC
using (TcpClient TwitchConnection = new TcpClient("irc.twitch.tv", 6667))
{
//This is what we will use to write commands to the IRC
using (StreamWriter TwitchWriter = new StreamWriter(TwitchConnection.GetStream()))
{
//If the shutdown event is signaled the loop will break and the thread will end
if (_shutdownEvent.WaitOne(0))
break;
//Sets the username
TwitchWriter.WriteLine("USER " + AccountArray[0] + "tmi twitch :" + AccountArray[0]);
//Authorises the account using their Oauth
TwitchWriter.WriteLine("PASS oauth:" + AccountArray[1]);
//Set the Nickname
TwitchWriter.WriteLine("NICK " + AccountArray[0]);
//Joins the twitch channel you're going to be spamming
TwitchWriter.WriteLine("JOIN #" + textBox1.Text);
//Sends your Message through the IRC to the Channel you are spamming
TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text + " " + R.Next(9999));
}
}
}
//Checks to see if the Account reader has reached the end of the file
if (TwitchAccountReader.EndOfStream == true)
{
//Resets the reader to the beginning so the spam can restart
TwitchAccountReader.DiscardBufferedData();
TwitchAccountReader.BaseStream.Seek(0, SeekOrigin.Begin);
TwitchAccountReader.BaseStream.Position = 0;
}
}
}
catch (Exception ex)
{
//Shows a message box with the exception error
MessageBox.Show(ex.Message);
}
}
}

The following user thanked Sloth for this useful post:

Boliberrys
10-19-2015, 03:53 AM #12
Boliberrys
^^ Sexy ^^
Originally posted by Sloth View Post
It could be the channel, sometimes it requires users to have verified emails. Also the chatbot function has been updated so copy and paste it in to the source here it is
    private void StartChatBot()
{
//Loops through the code inside until broken
while (true)
{
try
{
//Reads from a text file containing the user accounts in the same directory as the application.
using (StreamReader TwitchAccountReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "/users.txt"))
{
//Declaring strings
string AccountString;
string[] AccountArray;
//Reads a line from the file
AccountString = TwitchAccountReader.ReadLine();
//Basically it will read each line from the text file until it reaches the end
while ((AccountString = TwitchAccountReader.ReadLine()) != null)
{
//Splits the Line in to 2, [0] is the username, [1] is the Oauth
AccountArray = AccountString.Split(':'Winky Winky;
//Connects to thw Twitch IRC
using (TcpClient TwitchConnection = new TcpClient("irc.twitch.tv", 6667))
{
//This is what we will use to write commands to the IRC
using (StreamWriter TwitchWriter = new StreamWriter(TwitchConnection.GetStream()))
{
//If the shutdown event is signaled the loop will break and the thread will end
if (_shutdownEvent.WaitOne(0))
break;
//Sets the username
TwitchWriter.WriteLine("USER " + AccountArray[0] + "tmi twitch :" + AccountArray[0]);
//Authorises the account using their Oauth
TwitchWriter.WriteLine("PASS oauth:" + AccountArray[1]);
//Set the Nickname
TwitchWriter.WriteLine("NICK " + AccountArray[0]);
//Joins the twitch channel you're going to be spamming
TwitchWriter.WriteLine("JOIN #" + textBox1.Text);
//Sends your Message through the IRC to the Channel you are spamming
TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text + " " + R.Next(9999));
}
}
}
//Checks to see if the Account reader has reached the end of the file
if (TwitchAccountReader.EndOfStream == true)
{
//Resets the reader to the beginning so the spam can restart
TwitchAccountReader.DiscardBufferedData();
TwitchAccountReader.BaseStream.Seek(0, SeekOrigin.Begin);
TwitchAccountReader.BaseStream.Position = 0;
}
}
}
catch (Exception ex)
{
//Shows a message box with the exception error
MessageBox.Show(ex.Message);
}
}
}


Where it says:

TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text + " " + R.Next(9999));


R is not declared :P
10-19-2015, 03:55 AM #13
Sloth
Banned
Originally posted by Boliberrys View Post
Where it says:

TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text + " " + R.Next(9999));


R is not declared :P


Oh fuck sorry here
    TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text )
I was using a random number gen to test R9K bypassing Lol add my skype: KronosCloud and I"ll try to help
11-05-2015, 10:00 AM #14
Originally posted by Sloth View Post
A friend supplied me with them I did have 16k but alot were banned


Ok, thanks anyways!
11-07-2015, 03:17 PM #15
One question, do you know if the IRC network needs to respond to you? E.g. each field completed, data is sent back to make sure auth was complete. If no - then a VPN isn't needed, you can simply randomise the source address inside the IP packet header, so each user would be on a completely different and random IP address.
12-04-2015, 02:14 AM #16
AFG
The One and Only
Nice release man.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo