twitchdev / chatbot-python-sample

Apache License 2.0
99 stars 48 forks source link

Update to Python 3.9.1 #2

Open RikiRC opened 3 years ago

RikiRC commented 3 years ago

I have made few changes to made it work with Python 3.9.1 and updated API request.

Coincident commented 3 years ago

Thank you @RikiRC for the changes. Now the bot runs with the latest version of Python. However, it never connects. I just get a message saying: "Connecting to irc.chat.twitch.tv on port 6667..." and nothing happens for hours. Is this working for anyone else?

RikiRC commented 3 years ago

Hi @Coincident, I have tested it again and it works ok for me. Can you double check the parameters that you are providing for chatbot.py? Especially OAuth token, because you need to provide this parameter without oauth: prefix e.g.:

image

Sometimes this bot can't connect first try, so sometimes you have to restart it few times. But if it is connected to irc channel then you see message: _Joining #channel_name Joined #channelname

Also bot sends message to twitch chat when connected:

image

Coincident commented 3 years ago

Hello. Thanks for the reply. Yeah, I've double-checked. I do not have the "oauth:" prefix in the token string, I've removed it before. I tried starting & stopping the bot multiple times, it never works.

Also, there seems to be an error on line 22: https://github.com/twitchdev/chatbot-python-sample/pull/2/commits/853f9569eac222b8e04d0c5f3c54eb19c4b783c3#diff-ce7c8a3a3f07f8572f7bb29f6313e8feb4a61d0082a8555fcee60ca6aca2cba6L22 This: url = 'https://api.twitch.tv/kraken/users?login=' + channel Should be this instead: url = 'https://api.twitch.tv/kraken/users?login=' + username

Otherwise the bot will only work if channel == username; which means you're using your own Twitch account as the login for the bot. In my case I have made a separate account for the bot, so I had to change the line. Anyway, even with that fix the bot never connects, no matter how long I wait / how often I restart.

Edit: Nevermind. This is incorrect. There is no error on line 22.

erwan-b commented 3 years ago

Thanks work very well ! :ok_hand:

Coincident commented 3 years ago

Sorry about the last message; that was a big confusion on my behalf. I reverted the changes to the code and somehow the bot connected this time. I had tried this before and it didn't work. No idea what I did different this time... Now I consistently get the two messages: Joining #channel_name Joined #channel_name

But the bot never responds to any comments or messages, and I never see the "'Received command: ' + cmd" print. The "Connected!" message does not appear at first; it only appears if I use my actual browser to login with the bot's Twitch account and manually join the channel. But even like that, the bot does not respond to commands.

Coincident commented 3 years ago

Hello again, after several hours of experimenting and researching, I found the culprit of the problem: "channel" has to be entirely in lower-case!

https://discuss.dev.twitch.tv/t/python-bot-irc-problem-just-asking-for-explanation/30123

Now the bot finally works!

Coincident commented 3 years ago

@RikiRC awesome. That last commit will prevent the next people who try this to run into the same lower-case problem.

I would also recommend another change to prevent more problems: