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

When the function "end_prediction" is called, NoneType is called. #195

Closed kosame-kiri closed 1 year ago

kosame-kiri commented 1 year ago

create_prediction works correctly.

Traceback (most recent call last):
  File "D:\github\bgmc-manager\test.py", line 36, in <module>
    asyncio.run(start())
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "D:\github\bgmc-manager\test.py", line 33, in start
    await twitch.end_prediction(target_channel_user.id, prediction.id, PredictionStatus.CANCELED, prediction.outcomes[0].id)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python310\lib\site-packages\twitchAPI\twitch.py", line 2880, in end_prediction
    return await self._build_result('PATH', 'predictions', {}, AuthType.USER, [AuthScope.CHANNEL_MANAGE_PREDICTIONS], Prediction, body_data=body)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python310\lib\site-packages\twitchAPI\twitch.py", line 599, in _build_result
    response = await req(session, _url, auth_type, auth_scope, data=body_data)
TypeError: 'NoneType' object is not callable
from twitchAPI.pubsub import PubSub
from twitchAPI.twitch import Twitch, TwitchUser, Prediction
from twitchAPI.oauth import UserAuthenticator
from twitchAPI.types import AuthScope, ChatEvent, PredictionStatus
from twitchAPI.chat import Chat, EventData, ChatMessage, ChatSub, ChatCommand
from twitchAPI.helper import first
import asyncio

APP_ID = 'XXX'
APP_SECRET = 'XXX'
USER_SCOPE = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT,
              AuthScope.CHANNEL_READ_REDEMPTIONS,
              AuthScope.CHANNEL_READ_SUBSCRIPTIONS,
              AuthScope.CHANNEL_MANAGE_PREDICTIONS,
              AuthScope.CHANNEL_READ_PREDICTIONS]
TARGET_CHANNEL = 'xxx'

twitch = Twitch(APP_ID, APP_SECRET)
auth = UserAuthenticator(twitch, USER_SCOPE)

target_channel_user: TwitchUser = None

async def start():
    token, refresh_token = await auth.authenticate()
    await twitch.set_user_authentication(token, USER_SCOPE, refresh_token)

    global target_channel_user
    target_channel_user = await first(twitch.get_users(logins=[TARGET_CHANNEL]))

    prediction = await twitch.create_prediction(target_channel_user.id, 'test', ['y', 'n'], 5)
    await asyncio.sleep(7)
    await twitch.end_prediction(target_channel_user.id, prediction.id, PredictionStatus.CANCELED, prediction.outcomes[0].id)

if __name__ == '__main__':
    asyncio.run(start())