Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubSub not registering any events incoming from Twitch #62

Open
NanoSNAkeR opened this issue Jun 17, 2021 · 11 comments
Open

PubSub not registering any events incoming from Twitch #62

NanoSNAkeR opened this issue Jun 17, 2021 · 11 comments

Comments

@NanoSNAkeR
Copy link

I Started having problems with the PubSub service all of a sudden, It's not getting any input from twitch events. The strange thing is it used to work without a problem right before I started a stream, now it just says that everything connects successfully but it doesn't register any events incoming from Twitch, like channel points redeems, whispers or follows... I don't know what else to do...

Here's my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TwitchLib.Unity;
using TwitchLib.PubSub;
using TwitchLib.PubSub.Events;

public class TwitchPubSubTest : MonoBehaviour
{
    private PubSub _pubSub;

    //public string currentReward = "";
    //public string latestFollower = "";

    // Start is called before the first frame update
    void Start()
    {
        Application.runInBackground = true;

        _pubSub = new PubSub();

        _pubSub.OnChannelPointsRewardRedeemed += OnChannelPointsRewardRedeemed;
        //_pubSub.OnFollow += _pubSub_OnFollow;
        _pubSub.OnWhisper += OnWhisper;
        _pubSub.OnListenResponse += OnListenResponse;
        _pubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;

        _pubSub.Connect();
    }

    

    private void OnPubSubServiceConnected(object sender, System.EventArgs e)
    {
        Debug.Log("PubSubServiceConnected!");

        // CHANNEL_ID is the streamer channel ID the one that is like 12345678.
        // CHANNEL_ACCESS_TOKEN is the channel oauth token, which is validated for everything.

        _pubSub.ListenToWhispers(Secrets.CHANNEL_ID);
        _pubSub.ListenToChannelPoints(Secrets.CHANNEL_ID);
        //_pubSub.ListenToFollows(Secrets.CHANNEL_ID);
        _pubSub.SendTopics(Secrets.CHANNEL_ACCESS_TOKEN);
    }

    private void OnListenResponse(object sender, OnListenResponseArgs e)
    {
        if (e.Successful)
        {
            Debug.Log($"Successfully verified listening to topic: {e.Topic}");
        }
        else
        {
            Debug.Log($"Failed to listen! Error: {e.Response.Error}");
        }
    }

    //private void _pubSub_OnFollow(object sender, OnFollowArgs e)
    //{
    //    Debug.Log($"{e.Username}" + " Has followed!");
    //    latestFollower = $"{e.Username}";
    //    FollowThanks.instance.StartAction(latestFollower);
    //}

    private void OnChannelPointsRewardRedeemed(object sender, OnChannelPointsRewardRedeemedArgs e)
    {
        Debug.Log("A channel reward has been redeemed! " + $"{e.RewardRedeemed.Redemption.Reward.Title}");
        //currentReward = $"{e.RewardRedeemed.Redemption.Reward.Title}";
    }

    private void OnWhisper(object sender, OnWhisperArgs e)
    {
        Debug.Log($"{e.Whisper.Data}");
    }
}

And here's the console log for the script... as you can see it verifies everything successfully...

response

Also the other services, such as the Client and the API work correctly without any errors, bot reads chat, reads viewers, can answer to callouts etc...

If anyone can help I would appreciate it a lot!

@MelonSpeedruns
Copy link

I can confirm I'm having the exact same issue. My code is identical to yours.

@ZePilOt
Copy link

ZePilOt commented Jun 22, 2021

I have the same issue, reverted back to ListenToRewards.
It's strangely linked to rewards with images. If they don't have images, it's working (but you need to restart your app first : first rewards with images will break the event entirely)

@NanoSNAkeR
Copy link
Author

I have the same issue, reverted back to ListenToRewards.
It's strangely linked to rewards with images. If they don't have images, it's working (but you need to restart your app first : first rewards with images will break the event entirely)

Yeah, I also traced the problem to the new channel points function but I didn't know the images were the actual problem... most curious. Switched to the ListenToRewards as well and it seems to work like a charm.
Also found out that the Whisper function can also cause some problems too...

@stickermonster
Copy link

Just wanted to chime in--had the same issue, switching back to the old OnRewardRedeemed system worked just fine :)

I'm wondering why the custom image messes the redeem up--it must have something to do with how the message is formatted; the reward listener is looking for a specific first arg, but that arg must change to be the image when one is present.

@gengar1603
Copy link

I can confirm that OnChannelPointsRewardRedeemed still has problems with custom reward icons.

@LazyFangs
Copy link

To give closure to this issue (and because I invested nearly 6 hours going on the same journey as the rest of the guys here)

  1. The bug was using an older version of PubSub, which had incorrectly set the Image object as String instead of an object - hence the String parser threw up an "unexpected character {". Curly braces are not how you start a string. It was fixed at a later date than the current Release
    TwitchLib/TwitchLib.PubSub@e65f966#diff-dd87ee3df01f86fd8eb906d454236162c2742a7f7e0d0d81623fc910c1153660

  2. The current pre-release version has this fix already applied.

Sorry for the necro, but this problem drove me up a wall and I thought it only fair to have at least one more issue semi-closed

@MelonSpeedruns
Copy link

MelonSpeedruns commented Jan 22, 2022

I will try that and report today if the pre-release version indeed fixed it on my end. Thanks for letting me know!

EDIT: Hmm, it doesn't like it's working with PubSub version 3.2.3, which has the fix. I tried using the following code in a basic Console App using Visual Studio 2022:

using TwitchLib.PubSub;
using TwitchLib.PubSub.Events;

TwitchPubSub _pubSub = new TwitchPubSub();

_pubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
_pubSub.OnChannelPointsRewardRedeemed += OnChannelPointsRewardRedeemed;

_pubSub.ListenToChannelPoints("63469890");

_pubSub.Connect();

void OnChannelPointsRewardRedeemed(object? sender, OnChannelPointsRewardRedeemedArgs e)
{
    Console.WriteLine(e.RewardRedeemed.Redemption.Reward.Title);
}

void OnPubSubServiceConnected(object? sender, EventArgs e)
{
    _pubSub.SendTopics();
    Console.WriteLine("Connected to Twitch! Press Escape to exit.");
}

ConsoleKeyInfo input;
do
{
    input = Console.ReadKey();
} while (input.Key != ConsoleKey.Escape);

It works perfectly fine with the deprecated functions however.

@MeepsKitten
Copy link

I will try that and report today if the pre-release version indeed fixed it on my end. Thanks for letting me know!

EDIT: Hmm, it doesn't like it's working with PubSub version 3.2.3, which has the fix. I tried using the following code in a basic Console App using Visual Studio 2022:

using TwitchLib.PubSub;
using TwitchLib.PubSub.Events;

TwitchPubSub _pubSub = new TwitchPubSub();

_pubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
_pubSub.OnChannelPointsRewardRedeemed += OnChannelPointsRewardRedeemed;

_pubSub.ListenToChannelPoints("63469890");

_pubSub.Connect();

void OnChannelPointsRewardRedeemed(object? sender, OnChannelPointsRewardRedeemedArgs e)
{
    Console.WriteLine(e.RewardRedeemed.Redemption.Reward.Title);
}

void OnPubSubServiceConnected(object? sender, EventArgs e)
{
    _pubSub.SendTopics();
    Console.WriteLine("Connected to Twitch! Press Escape to exit.");
}

ConsoleKeyInfo input;
do
{
    input = Console.ReadKey();
} while (input.Key != ConsoleKey.Escape);

It works perfectly fine with the deprecated functions however.

It does seem to work fine, I think you were just missing OAuth in SendTopics

@midnitefactory
Copy link

The issue persists even with the most up to date version of this library despite what's said in the comments. Even with OAuth properly authorized and sent via SendTopics it's the OnChannelPointsRewardRedeemed function that causes PubSub to crash, using OnRewardRedeemed fixed everything.

@HugoVG
Copy link

HugoVG commented Aug 20, 2023

The issue persists even with the most up to date version of this library despite what's said in the comments. Even with OAuth properly authorized and sent via SendTopics it's the OnChannelPointsRewardRedeemed function that causes PubSub to crash, using OnRewardRedeemed fixed everything.

i'm facing the same issue of it not firing, are you still using client.ListenToRewards(id); or are you using client.ListenToChannelPoints(id);?

@midnitefactory
Copy link

The issue persists even with the most up to date version of this library despite what's said in the comments. Even with OAuth properly authorized and sent via SendTopics it's the OnChannelPointsRewardRedeemed function that causes PubSub to crash, using OnRewardRedeemed fixed everything.

i'm facing the same issue of it not firing, are you still using client.ListenToRewards(id); or are you using client.ListenToChannelPoints(id);?

ListenToRewards(id) is what I use and it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants