mitchwadair / tesjs

Streamline your Twitch EventSub JavaScript integration with TESjs
https://www.tesjs.net/
MIT License
29 stars 6 forks source link

[QUESTION] error when i subscribe to any event #57

Closed TiotBenjy closed 2 years ago

TiotBenjy commented 2 years ago

Write your question Hello, i need help to fix an error when i subscribe to any envent BUT evnets sub works correctly I recieve all the event i subscribed.

my problem is : Cannot read properties of undefined (reading '0')

Additional context the complete error :

Mon, 12 Sep 2022 18:19:08 GMT - TESjs - Adding notification listener for type channel.subscription.gift Mon, 12 Sep 2022 18:19:08 GMT - TESjs - Subscribing to topic with type channel.subscription.gift and condition [object Object]

TypeError: Cannot read properties of undefined (reading '0') at EventManager.queueSubscription (/var/www/vhosts/xxxxxxx.fr/xxxxxxxxxx.fr/node_modules/tesjs/lib/events.js:49:29) at /var/www/vhosts/jesuiskristoff.fr/bot.jesuiskristoff.fr/node_modules/tesjs/lib/tes.js:189:62 at new Promise () at TES.subscribe (/var/www/vhosts/jesuiskristoff.fr/bot.jesuiskristoff.fr/node_modules/tesjs/lib/tes.js:189:16) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5)

Environment:

mitchwadair commented 2 years ago

Hmm.. I did some playing around and found what might be the problem. Does the client ID you're using have the correct authorization scopes? For channel.subscription.gift, you need the channel:read:subscriptions scope. If you are unsure how to give yourself that scope, you can check out my comment in #13 here to get it set up.

As a personal note: filed #58 to improve error messaging here

BUT evnets sub works correctly I recieve all the event i subscribed

When you say this, do you mean that you're still receiving the events properly? Are you using the Twitch CLI to test this?

TiotBenjy commented 2 years ago

Yes I receive event properly because when I use rewards the event is correctly triggered and message is sent in the chat. Today I'm resub on the channel and the event works perfectly.

I don't use Twitch CLI.

I don't understand this error ^^

mitchwadair commented 2 years ago

I see, okay. So the other thing that may be happening is that you already had a subscription made with that condition. If you call

tes.getSubscription("channel.subscription.gift", { broadcaster_user_id: <your-id> }).then(console.log);

You'll probably see that you've already made that subscription and that is why your events are functioning properly. When an existing subscription is present Twitch returns a 409 response when attempting to subscribe to it again. #58 should also help with identifying this case

mitchwadair commented 2 years ago

Just released v0.7.1 that should provide better output for you

TiotBenjy commented 2 years ago

Okay I will update the module and test it.

Thanks !

TiotBenjy commented 2 years ago

Yes that's the problem !

Thank you for your help and your reactivity !

Now i have : Tue, 13 Sep 2022 15:46:24 GMT - TESjs - Adding notification listener for type channel.subscription.gift 0|Toffibot | Tue, 13 Sep 2022 15:46:24 GMT - TESjs - Subscribing to topic with type channel.subscription.gift and condition { broadcaster_user_id: 'xxxx' } Error: 409 Conflict: subscription already exists at TES.subscribe

mitchwadair commented 2 years ago

Awesome, glad you got it figured out :+1:

You're welcome, happy to help :smile: