Cant login as bot in python

Trying to receive messages from chat continuously, but noticed that twitch disconnects me after approximately 10 min, so I created app here and got access_token by sending client_id and client_secret to After that I try to send pass and nick using socket but I receive NOTICE * :Login unsuccessful

import socket
import requests

r =''
                  f'&scope=chat:read chat:edit channel:moderate')

resp = r.json()

PASS = resp['access_token']

s = socket.socket()
s.connect((Host, Port))
s.send(f"PASS oauth:{PASS}\r\n".encode("utf-8"))
s.send(f"NICK {Nickname.lower()}\r\n".encode("utf-8"))
s.send(f"JOIN {Channel}\r\n".encode("utf-8"))

while True:
    rec = s.recv(1024).decode("utf-8")

You cannot use a token of type “client_credentials” to login to Twitch chat.

It doesn’t represent a user

You need a user Access Token:

A token of type client_credentials won’t let you login to chat.

It doesn’t have scopes on it (even though you requested)

To login to chat you need a user token (response_type code) that has the relevant chat scopes on it, and the access_code you exchange for needs to be for the user of “nickname” in your code.

The oAuth loop is done separately to your main bot code flow, since it needs a web server (even a localhost one) and user interaction to validate/access the permission(s), and you just throw a refresh token loop in instead.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.