Prerequisites:
- Unity 2017.1+
- Clone or download repository from https://github.com/swiftyspiffy/TwitchLib
- (Download all dependencies of TwitchLib)
- In Unity: Edit > Project Settings > Player
- Scroll down to Api Compatibility Level and select “.NET 4.6” or higher
See extensive guide to see how to compile DLL and avoid TLS problems.
Prerequisites:
- Unity 2017.1+
- SourceTree
- Visual Studio
Example with SourceTree
Example using Visual Studio
- Open TwitchLib solution in Visual Studio See GIF
- Set to Release mode See GIF
- Build TwitchLib solution See GIF
- Confirm that you now have these DLL files: See GIF
- Newtonsoft.Json.dll
- TwitchLib.dll
- websocket-sharp.dll
- Create new Unity project See GIF
- In Unity select: Edit > Project Settings > Player
- Scroll down to Api Compatibility Level and select “.NET 4.6” or higher See GIF
- Import TwitchLib DLLs See GIF
Create a twitch account for your bot
- Navigate to Connections and register your new app See GIF
- Create a new Client Secret and copy to notepad for later See GIF
- Create new OAuth token with https://twitchtokengenerator.com and copy to notepad for later See GIF
- Create new script See GIF
- Gather relevant data See GIF (part 1), See GIF (part 2)
- Try to make connection See GIF
- Attempt to run code See GIF
- Fix Mono TLS Exception See GIF
TLS Fix:
public bool CertificateValidationMonoFix(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool isOk = true;
if (sslPolicyErrors == SslPolicyErrors.None)
{
return true;
}
foreach (X509ChainStatus status in chain.ChainStatus)
{
if (status.Status == X509ChainStatusFlags.RevocationStatusUnknown)
{
continue;
}
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
bool chainIsValid = chain.Build((X509Certificate2)certificate);
if (!chainIsValid)
{
isOk = false;
}
}
return isOk;
}
Now it's just a matter of exploring the API's provided by TwitchLib and hooking into the events you need :)