question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Twitch Gifting messages

See original GitHub issue

Twitch introduced a new feature which appears to add a new USERNOTICE message with a new msg-id.

https://blog.twitch.tv/give-the-gift-of-twitch-with-subscription-gifting-af4532ee137c

Would be great to have this supported by tmi.js

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
wobYYcommented, Nov 19, 2017

Well if you want to you can add it yourself in the node_modules/tmi.js/lib/client.js

I added this at line 606(Screenshot):

// Handle subgift
                    else if (msgid == "subgift") {
                        var username = message.tags["display-name"] || message.tags["login"];
                        var recipient = message.tags["msg-param-recipient-display-name"] || message.tags["login"];
                        var plan = message.tags["msg-param-sub-plan"];
                        var planName = _.replaceAll(_.get(message.tags["msg-param-sub-plan-name"], null), {
                            "\\\\s": " ",
                            "\\\\:": ";",
                            "\\\\\\\\": "\\",
                            "\\r": "\r",
                            "\\n": "\n"
                        });
                        var prime = plan.includes("Prime");
                        var userstate = null;

                        if (msg) {
                            userstate = message.tags;
                            userstate['message-type'] = 'subgift';
                        }

                        this.emit("subgift", channel, username, {prime, plan, planName}, msg, userstate);
                    }

How to use it(wasn’t sure if msg is always null so i left it there, the important thing is, it works and i’m fine with it as long as it works 😄): Screenshot

I tested it in summit’s chat, it worked so I’m fine

EDIT: No Prime, so can remove that. Edited the script again, testing it atm

EDIT 2: Excuse my stupidness, it’s 1AM where I live, I’m not able to fall asleep so I thought I might as well add this to my bot.

New client.js code:

// Handle subgift
                    else if (msgid == "subgift") {
                        var username = message.tags["display-name"] || message.tags["login"];
                        var recipient = message.tags["msg-param-recipient-display-name"] || message.tags["login"];
                        var plan = message.tags["msg-param-sub-plan"];
                        var planName = _.replaceAll(_.get(message.tags["msg-param-sub-plan-name"], null), {
                            "\\\\s": " ",
                            "\\\\:": ";",
                            "\\\\\\\\": "\\",
                            "\\r": "\r",
                            "\\n": "\n"
                        });
                        var userstate = message.tags;

                        this.emit("subgift", channel, username, {plan, planName}, userstate);
                    }

Your script code

1reaction
AlcaDesigncommented, Feb 21, 2019

Updated with c06d7662c446c612ecc43e51071aef4182d2605f – Available in upcoming 1.4.0, which might be released later today.

And for https://github.com/tmijs/tmi.js/issues/262#issuecomment-395868342, yes and you can get that from the userstate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to Custom Messages - Twitch Help
Now when you subscribe and resubscribe, you will have the option of sending a shout-out to the streamer you are supporting. Not only...
Read more >
Gift Sub message - Twitch UserVoice
I'd like the ability to put a message in a gift sub that gets posted for everyone to see with the notification of...
Read more >
How to Gift Subs on Twitch – a Quick Guide
If you really like a streamer on Twitch, you can support them by taking out a subscription to their channel. Subscribers pay a...
Read more >
Twitch Support (@TwitchSupport) / Twitter
Streamers and mods can: Use /pin or pin directly from chat ⏱️ Customize a timer or manually control pin durations Viewers can also...
Read more >
Twitch Gift Cards - Email Delivery (US Only) - Amazon.com
Please see additional terms and conditions, including instructions for redeeming this card, at twitch.tv/legal/giftcard. For customer service, visit: help.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found