Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
254 stars 38 forks source link

Could someone please tell me the reason? #264

Closed CureSaba closed 1 year ago

CureSaba commented 1 year ago
from twitchAPI import Twitch
from twitchAPI.types import AuthScope, ChatEvent
from twitchAPI.chat import Chat, EventData, ChatMessage, ChatSub, ChatCommand
import asyncio

APP_ID = 'ID'
APP_SECRET = 'SECRET'
token = 'Token'
TARGET_CHANNEL = 'channel'
USER_SCOPE = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT]
async def run():
    twitch = await Twitch(APP_ID, APP_SECRET)
    twitch.auto_refresh_auth=False
    await twitch.set_user_authentication(token,USER_SCOPE)
    chat = await Chat(twitch)
    chat.start()
    await chat.send_message(TARGET_CHANNEL,"test")
    chat.stop()
    await twitch.close()
asyncio.run(run())

I want to send a message "test" to the chat The sample project works, so the key is not wrong But when I run this I get an error ValueError: can't send message: bot not ready

OS: Windows11 Python Version: Python 3.11.4 twitchAPI Version: 3.11.0

stolenvw commented 1 year ago

you are trying to send the message without giving it time to fully connect and join channel

Teekeks commented 1 year ago

you also just dont join the channel at all in this example (use either initial_channel or join channels in the ready event)