PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
791 stars 163 forks source link

Issue with the lib handling the response from the edit #383

Closed BadChromer closed 1 year ago

BadChromer commented 1 year ago
broadcaster = client.create_user(CHANNEL_ID, 'CHANNEL_NAME')

async def edit_reward(title: str, paused: bool, cost: int):
    main_reward = (await broadcaster.get_custom_rewards(token=USER_OAUTH_TOKEN, only_manageable=True))[0]
    await main_reward.edit(token=USER_OAUTH_TOKEN, title=title, paused=paused, cost=cost, max_per_user_per_stream=None)

async def main():
    await edit_reward(title='TEST', paused=False, cost=10)
    await client.start()

client.loop.run_until_complete(main())

So the code seems like working, but when i call

await edit_reward(title='TEST', paused=False, cost=10)

It updates the reward and then throws TypeError:

Traceback (most recent call last): File "c:\Users\user\Downloads\twitch_bot\twitch_bot.py", line 119, in client.loop.run_until_complete(main()) File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "c:\Users\user\Downloads\twitch_bot\twitch_bot.py", line 100, in main print(await edit_reward(title='TEST', paused=True, cost=10)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\user\Downloads\twitch_bot\twitch_bot.py", line 34, in edit_reward await main_reward.edit(token=USER_OAUTH_TOKEN, title=title, paused=paused, cost=cost, max_per_user_per_stream=None) File "C:\Program Files\Python311\Lib\site-packages\twitchio\rewards.py", line 239, in edit for reward in data["data"]: ~~~~^^^^^^^^ TypeError: list indices must be integers or slices, not str

github-actions[bot] commented 1 year ago

Hello! Thanks for the issue. If this is a general help question, for a faster response consider joining the official Discord Server

Else if you have an issue with the library please wait for someone to help you here.

IAmTomahawkx commented 1 year ago

@BadChromer ive pushed a potential fix for this, can you try pulling from git and testing it?

BadChromer commented 1 year ago

@IAmTomahawkx Yeah, the fix helped. It's working fine now. Thank you.

IAmTomahawkx commented 1 year ago

Will close this with next release