IRC Chat Bot randomly skips writing

Hello everyone!

I used this source for my first Twitch Chat Bot, and it was working absolutely fine for like 3-4 months:

I modified it and bot is not spamming anything, it writes only once every 2-3 minutes and the messages are always different. (There are no ! commands, I use Nightbot for that). The bot obviously is /mod

As already said, it was working fine for months, until these last weeks, where I noticed a huge amount of “skipped” message, there is no particular rule or timing, I checked kinda every scenario, the bot just doesnt write in chat, like if the credentials are wrong, or it loses the connection. But the next round, after 2 min~, it writes back again, so it isn’t shadowbanned? Otherwise I would be locked up for 30minutes or something.
I didn’t change one single line and all of the sudden this weird behaviour happened, forcing me to do some changes:

  • Original code was including a Ping once every 5 minutes, but since it was writing only once in 2 minutes I never used the Ping function, and it always worked flawlessly for months. Now since the skipped messages, I included back the Ping, but still it doesn’t write some messages.
  • I changed the irc.twitch.tv to irc.chat.twitch.tv, still skipping some messages
  • I forced the 6667 port on my windows settings, still skipping some messages
  • I tried to change the oauth token requesting a new one, still skipping some messages.
  • I tried to launch multiple times the same bot, like let’s say bot1, bot2, bot3, and they all do the same problem, sometimes bot1 doesn’t write, or sometimes bot2 doesn’t write, or sometimes bot3 doesn’t write. The curious thing is when bot1 skips message, the bot2 doesn’t, or bot3 skips message but bot1 doesn’t, so the bot is not banned, and it didnt lose the connection…Even if I launch multiple istances of the bot, they don’t interfere with each other, but every one of them, once in a while, skips message.

Its so random that I don’t know where to ask for help, I know the code is correct, otherwise it shouldn’t write at all (at the end if worked for months, so why it stopped now?), but now lets say 1 out of 15 times, it skips writing. Again, no particular reason, or timing, and no dupicate message.

I tried contacting Twitch and I got an auto-reply message based on the keywords on my message so I don’t even waste my time on Twitch bot assistance.

Im looking for some real human person that can help me figuring out what could be the issue, because Im literally becoming crazy.

Any help is appreciated, many thanks! And have nice holidays!

Greetings

It sounds like your bots are encountering some error but you aren’t logging it. Show us the raw logs of what your bot is sending to Twitch, and what response you’re getting from Twitch.

Im still learning C# but the main command that I always used and never failed is

irc.SendPublicChatMessage(“Text here”);

There are different variations like

irc.SendPublicChatMessage("/subscribers");
irc.SendPublicChatMessage(“Text here”);
irc.SendPublicChatMessage("/subscribersoff");

It doesn’t matter if its 1 line chat, or 3-5 lines combo chat, I’ve used this code for months and never encountered a single problem (and I wasn’t even using Ping). There were even multiple bots overlapping at the same time so definitely it isn’t a confliction between bots. I don’t know what happened in these last weeks. I am pretty suire it is something related to the bot account, or the channel where it writes.

Lets assume for example that at 10:00am it needs to send a message, this is what usually happens

Case 1 (Normal, worked for months): bot1, bot2, bot3, etc… all send correctly the message in Chat without problems at the same exact time (milliseconds precision)
Case 2 (recent bug): Some of the bot, maybe bot1, or bot3 fails to send the message, but at the same time (again, milliseconds precision) the other bots write successfuly. So its kinda a paradox, if some bot is “disconnected” from twitch, how can other bots work fine?

I don’t know how to debug the problem, sometimes it fails after 6 messages, sometimes after 10 or 20 or 30, it just insanely random. I tried to run 1 single bot, adding Ping, disconnect from Twitch, reset the Router… Nothing changed, since weeks the bot account randomly decides to skip messages. Is this a shadowban or something?

I have literally no idea of what is happening, considering that for months I never encountered a problem.

Without knowing what you’re sending to Twitch, and what, if any, errors Twitch are sending you it’s tough to know what is going on.

Im trying to debug but I can’t find the solution, the ping is sent correctly and I receive the “pong” aswell…

Now I noticed another new anomaly, if the message is multiple lines like

irc.SendPublicChatMessage(“Text 1”);
irc.SendPublicChatMessage(“Text 2”);
irc.SendPublicChatMessage(“Text 3”);
irc.SendPublicChatMessage(“Text 4”);

it skips some lines. This happens way less often, usually it skips the whole block, but I noticed that rarely it does like

Text1
Text3
Text4

or

Text2
Text3
Text4

and so on…

There is like 100ms delay between those commands and they NEVER failed in all these months I used the bot. I never touched the code and now, all these errors without a reason…

This pure randomness is driving me insane.
Its like everytime that it needs to write something, it RNG to decide if to write or not. I swear in all these months it never failed one single time.

Also, another weird anomaly is that sometimes (very rare, but it happened), the moderator badge doesn’t appear in chat, but 100ms later, it comes back. This means my bot got autobanned by another bot for using certain text that is reserved only to mods.

I can’t be connected to Twitch succesfully, then like “credentials wrong” after 100ms, and then “credentials right” again after 100ms. Or now “normal user”, and 1 second later is moderator again. It makes no sense in my head

I start to think that there is something completely broken on Twitch side, sadly the assistance is non-existent and I don’t know anyone that has a similar problem.

I will try to use the same code, which I strongly believe it doesnt need to be changed, but with another new account, and see if things change.

I googled pages and pages and didn’t find anything slighty remoted to this problem. If there was a massive bug on Twitch recently, there would be tons of posts already, but I see only mine apparently. And I don’t know anyone to talk with.

Sorry for not being able to provide detailed infos, Im doing my best, again if with a new account it wont work I guess Im done at this point

It’s not even the channel. I tried with another channel, with another bot credentials, and still some messages are skipped. But the “test bot” that writes every 2 minutes in chat, never fails. And the command to write is exactly the same

So I am really lost at this point. Why bot1 suddenly doesn’t work after months, but bot2 (which has the same code, kinda) never fails?

I don’t understand why at the same exact time, bot2 cant write but bot1 can instead, this is the classic computer paradox that keeps me awake at night.

Any help?

As I’ve tried to previously explain, we don’t have much info to go on. We don’t know what your code is, we don’t have raw logs of what you’re sending to Twitch, or what Twitch is sending to you (which may include error messages when you attempt to send messages to chat but it fails).

You’ve explained the problem in detail yes, some times messages don’t show in chat, but that’s not sufficient for any of us to attempt to diagnose what the issue may be with any certainty.

I think I managed to debug the problem. This is what I got as reply from the server when the message failed:

Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host

I googled it, and they said to add the line

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

(I did it and didn’t work, still skips some messages)

But since that topic is old, they said after that its not longer necessary to write that on NetFramework 4.6, which is guess what, It’s what I used for the bot for all these months.

So back to the point: the code is correct and it does what he wants without a reason, basically. I will pay anyone who can help me.

Sounds like your bot simply lost connection / the connection was closed (as the error message states) for whatever reason.

Possible reasons I could think of, out of my hat, would be

  • Stricter handling not not properly getting replies to PING messages (check your bot does properly handle those).
  • Simple connectivity problems (unstable connection) from the internet connection or the machine the bot(s) run on .
  • Twitch having issues (which in the last few days it actully did have a bit) which causes connections to drop.

And the messages being “skipped” are the ones the bot tries to send while the connection hasn’t been reestablished, yet.
So the bot sould/should only try to send messages if a connection is properly established.

1 Like

Uhm yeah but the thing is the moment lets say bot1 fails to write, bot2 writes successfully, and they have both the same credentials so it’s kinda a paradox (correct me if Im wrong) that the same user is connected and disconnected at the same exact time on the same channel.
About unstable connection, I use Ethernet and my connection has always been pretty good, but maybe there are some problems from my ISP, who knows.

And Twitch, right now as I’m writing, is completely broken, all users are “ghost” like the account doesn’t exist, the chat doesn’t load, and much more (I checked 4-5 random streamers and they are all bugged as hell)

So if I exclude a Twitch problem, I was thinking of keeping the line

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

But as already said Im not so advanced in programming, so my question is, should I change the code like this:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
irc.SendPublicChatMessage(“Text 1”);
irc.SendPublicChatMessage(“Text 2”);
irc.SendPublicChatMessage(“Text3”);

Or should I write

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
irc.SendPublicChatMessage(“Text 1”);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
irc.SendPublicChatMessage(“Text 2”);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
irc.SendPublicChatMessage(“Text3”);

Thanks for any help, appreciated!

That’s incorrect. Each connection is it’s own individual thing, regardless of if they are connected as the same user or not. It’s possible for 1 connection to have an issue but the other not, and then at a later time the connection that was previously fine could then have an issue.

Oh okay got it.
I just assumed that because I ran multiple istances at the same time (which are basically 100% clones), so if Host accepts “client1” I don’t see why it shouldn’t accept “client2” which is a perfect clone (in fact it never failed), but this is another story and at this point I can say for sure that the problem is a connection drop for some reason, or a twitch problem, specially considering these last days. It looks kinda unstable.

What about the code, should I force the protocol before each line of irc command or just one time before the 3-4 lines chunk? Sorry for the noob-ish question, Im still learning.

Setting the protocol is to do with the connection itself, once set it should have no further impact (and should be set before connection is established, as adjusting connection settings after a connection already exists may not do anything at all).

I’m not a c# dev though, so you should reach out to someone who is, and if the developer of that bot isn’t available you should try a different library.

1 Like

Thats perfect, Im gonna put it before the credentials then.

After this Twitch bad period Im curious to see the result.

Thank you so much for your time, I hope this topic will be helpful for someone!

I will update in some weeks