Making the bot run - How to build a Twitch bot in Python - Part 1

Making the bot run - How to build a Twitch bot in Python - Part 1

Carberra

4 года назад

28,570 Просмотров

Welcome to the series where I teach you how to build a Twitch chat bot in Python! Below are the links to the stuff you'll need:

The GitHub repository: https://github.com/Carberra/twitch-bot-tutorial
Python: https://www.python.org/downloads/
Twitch Devs: https://dev.twitch.tv/
Twitch token generator: https://twitchapps.com/tmi/
DB Browser for SQLite: https://sqlitebrowser.org/dl/

Some other awesome links for you:
- Superboo: the gaming channel I've run for far too long: https://bit.ly/superboo-channel.
- Discord: I have a Discord server! Come check it out here: https://bit.ly/carb-discord.
- Patreon: If you like the videos, consider donating! It would help out so much, and you even get special benefits. Win-win!: https://bit.ly/carb-patreon.

If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.

#python #twitch #bot

Тэги:

#pyfhon #pytho #pytbon #pytjon #ptyhon #pytyon #ptthon #pyyhon #pythn #pythoh #pythpn #ython #pytgon #pyhon #pytohn #phthon #oython #pthon #pyghon #pythoj #pythno #pythkn #ypthon #pytuon #lython #pyrhon #pythom #pythob #puthon #pgthon #python #pyhton #pythln #pythin #pytnon #pyton
Ссылки и html тэги не поддерживаются


Комментарии:

Fuzzy Images
Fuzzy Images - 18.02.2022 00:27

I am getting the KeyError: 'users' I've seen you say that the OWNER has to be lowercase, but that does not seem to be resolving the issue for me.

Ответить
Sean Fuentes
Sean Fuentes - 19.01.2022 14:28

For anyone who comes across this in the future this no longer works as the v5 api is deprecated and can no longer be used by new users and will be completely shut down in february

Ответить
boopidoop
boopidoop - 08.10.2021 04:50

hey, i've got this working for everything except the "Now online." message. any advice, or eta on the new tutorial?
this is my first time making a twitch bot and i'm fixated on using python because i want to add twitch integration to the sims 4 (which uses python)

Ответить
C C
C C - 25.09.2021 03:36

Ok, so after a bunch of searching for other python bot builds that still had errors popping up with no one in the comments able to explain fixes, I found a way around for atleast this portion of the self.channel_id = resp["users"][0]["_id"] KeyError: 'users'. The Discord let me know that "a few months ago they deprecated twitch v5 API fully. If you did not access it before then, you no longer can" which was actually really helpful to know. I found that they now have twitchAPI.twitch which is what you will need for this fix. Follow this entire first video and then pip install twitchAPI. Next, in your Import do " from twitchAPI.twitch import Twitch" . Now, under the NAME, OWNER include "twitch = Twitch('your_app_id', 'your_app_secret')". NOTE: App ID and APP SECRET are 2 diff things if you didn't know this already. Now, the 3rd and final step (and again, this is just to be able to replicate what is shown here on screen, I have not yet tested all the other vids and the project as a whole) remove lines 43-46 (the one starts with 'url' in it) and replace it with (Had to include a Reply due to text limits so check below)

Ответить
C C
C C - 24.09.2021 14:44

I'm only 8 minutes in and I HIGHLY suggest if following along and typing it out that you watch it at .50 speed. Not only is it easier than pausing and starting every few seconds, it makes him sound drunk and the typos really play into the idea. 10/10

Ответить
Dan Howe
Dan Howe - 23.07.2021 03:58

Now that api v5 is shutting down, will you be doing a new tutorial for api v6, or just a quick video explaining how to migrate to a new version

Ответить
Ack Peck
Ack Peck - 20.07.2021 14:45

Amazing tutorial! Just what I was looking for.
Does this still work?
I keep getting KeyError: 'users', when running the bot. I have reset the oauth token, and checked the client ID to be correct. NAME and OWNER are with lower case letters aswell.

Thanks

Ответить
egirlkaywa
egirlkaywa - 26.05.2021 14:13

Could you please help me set it up in discord!! it would mean a lot to me

Ответить
Michael Barley
Michael Barley - 09.05.2021 18:25

Could this bot be placed on anyones channel not just your own?

Ответить
Darkcode ninja
Darkcode ninja - 01.05.2021 21:33

i'm getting an error with self.channel_id = resp["users"][0]["_id"] , saying that the list is out of range. has the standard for the user's ID changed??

Ответить
Noel
Noel - 21.04.2021 23:07

I run the bot, no errors, but also no message on the chat

Ответить
X V
X V - 20.04.2021 18:32

Hi yes I wanna do this but will I loose followers during time or not also as well do I need a vpn just in case ?

Ответить
Daniel Romero Alvarado
Daniel Romero Alvarado - 19.04.2021 18:09

¡This is a really nice video! However, when trying to get the channel_id, my response is {'_total': 0, 'users': []}, so consequently I cannot get the channel_id. Do I have to wait some time for the application to be registered in the Twitch API? Or why is this problem happening?

Ответить
(ARCHIVED) Aaliyah Wolf
(ARCHIVED) Aaliyah Wolf - 19.04.2021 16:31

Heyo,
overall q: must I use Python 3.8 or can I use 3.9 for the IC + IRC requests?

TLDR: I believe I got everything correct but the code keeps saying "requests not found" I double checked everything and in your git hub. It said to instal "py -3.8 -m pip irc requests" so I did, however, I got the error "Python 3.8 not found! "
I use 3.9.1, so I'm assuming I need 3.8 to use this or is there a newer version I could use for 3.9?

Thank you for your time!

Ответить
30STMcwa
30STMcwa - 18.04.2021 16:53

Hey. Nice tutorial! I read the comments and saw that people had the same problem as me. I have checked everything several times and I do not understand where I am making a mistake.

Traceback (most recent call last):
File "C:\Users\...in <module>
bot = Bot()
File "C:\Users\...in _init_
self.channel_id = resp["users"][0]["_id"]
IndexError: list index out of range

Maybe something has changed since then? What should I check exactly? Can anyone help? Thank you in advance for your time.

Cheers!

Ответить
1nsane
1nsane - 25.03.2021 14:57

this video is amazing, can I know how do I add this bot to other channels to ???

Ответить
Stingmynuts
Stingmynuts - 20.03.2021 14:38

Does this still work :/

Ответить
Tenneny T
Tenneny T - 17.03.2021 20:35

Hi, thanks for the tutorials, Just out of curiosity, is there a specific reason you chose to use the library, I'm thinking about using twitchio for my bot, is that a bad choice?

Ответить
Dragon Bullet
Dragon Bullet - 14.03.2021 08:12

I have problem where I have all of the code in and when I run it I never get the "Now online." message sent in the chat. I did check's using prints and in the on_welcome def it makes it through all of the code in there but I never see a message in the chat so I was wondering what may be happening here

Ответить
Ryycs
Ryycs - 13.03.2021 21:47

How can I join more than one Channel?

Ответить
Ryycs
Ryycs - 10.03.2021 14:02

What should come up in the console when I am running the code?

Ответить
Felix
Felix - 07.03.2021 20:07

Hey I'm not really into programming. How can I send a message defined in the code. Some thing like that: send_message(self, "hi")

Ответить
Emilio Schmidt
Emilio Schmidt - 21.02.2021 22:03

Is it possible to make a bot which reads other people's chat, so I'm not the owner?

Ответить
0ne Peach
0ne Peach - 10.02.2021 05:05

Thank you very much for the tutorial!
I want to ask for help. The bot can't read colored messages written with /me. For example, if somebody write in the chat"/me doing something" bot don't see it. Is it possible to read these messages too?

Ответить
Nerf Matt
Nerf Matt - 29.01.2021 04:58

What can a Twitch bot do?

Ответить
magic_dot_exe
magic_dot_exe - 19.01.2021 02:03

Loving the tutorial so far but I can't get my bot to run. I've made sure my code looks exactly like yours (other than the NAME, token, etc.) but I'm not sure what's wrong.

Ответить
Viser les étoiles
Viser les étoiles - 07.01.2021 12:44

Do you have to be live for it to work ? I tried debugging the "self.channel_id" part because I got a "list index out of range", and this is what "resp" printed me : {'_total':0,'user':[]}

EDIT : After some code tweaks, it appears that using my channel name in the "url" string instead of my bot name fetches something. And due to this, I see my own account send a message in the offline twitch chat, which isn't what's expected, right ?

Ответить
Zedfear Needs Help
Zedfear Needs Help - 03.01.2021 16:52

Download link for the bot?

Ответить
ondrash
ondrash - 19.12.2020 04:55

Hey, where can i copy the copyright information ?

Ответить
The Boomer
The Boomer - 28.11.2020 04:28

When I run mine I get the error:
File "my file thing", line 42, in <module>
bot = Bot()
File "my file thing", line 21, in _init_
self.channel_id = resp["users"][0]["_id"]
IndexError: list index out of range

It worked before with the NAME and OWNER of the ones shown in the vid but with mine, it isn't working.

Ответить
The Boomer
The Boomer - 28.11.2020 04:24

To run on my own stream, what should I put for NAME and OWNER? my twitch id that I'm streaming on is Boom9er
A quick reply would be amazing. THANKS = True

Ответить
Kozie
Kozie - 09.11.2020 23:13

So you cant connect to some random channel since you need to log in to the channel?

Guess I'll just go with js and use a twitch-irc node package which seems way more flexible and less complicated 😄

Ответить
curiouser
curiouser - 06.11.2020 10:49

Great tutorial! I was wondering if the bot also works if I want it to enter another stream and listen to the chat.

Ответить
Nukinhas 55
Nukinhas 55 - 23.10.2020 19:59

which is this app?

Ответить
Just Thomas
Just Thomas - 19.10.2020 07:05

[Solved]
Howdy, I've tried to get your code to function and the init function executes properly but then nothing.
No error message, no program halt, no message in the stream chat - nothing.
I checked the resp response and it has all the expected info ({'_total': 1, 'users': [{'display_name': ...) so the issue seems to step from something later than that.

Any help or insight would be appreciated. Thanks for the help so far getting started.

Ответить