Giter VIP home page Giter VIP logo

twitchrequest's Introduction

What is Twitch Requests?

Twitch Requests is basically an advanced EventEmitter which adds a 'live' listener and 'unlive' listener. It can be used to detect if a streamer has gone live

Installation

npm install twitchrequest

const { Client } = require('twitchrequest');

const options = {
    // The channels you are listening to (all in lowercase)
    channels: ["destiall"],

    // Your client ID
    client_id: "your client id",

    // Your client secret
    client_secret: "your client secret",

    // The interval it will check (in seconds)
    interval: 3
};
const client = new Client(options);

client.on('live', (data) => {
    console.log(`${data.name} is now live! Streaming ${data.title} on ${data.game}! Started at ${data.date}`);
});

Events

This event is called when a channel included in the options goes live.

client.on('live', (streamData) => {
    // Do stuff
});

This event is called when a channel included in the options stops streaming.

client.on('unlive', (streamData) => {
    // Do stuff
});

This event is called when a user follows a channel EXPERIMENTAL.

client.on('follow', (userData, streamData) => {
    // userData is the user that followed
    // streamData is the StreamData that the user followed to
});

This event is called every interval set in the options.

client.on('debug', (streamData) => {
    // Do stuff
});

If you want subscription events or chat events, use npm i tmi.js instead!

Methods

This method can be used to get a specific StreamData of a channel.

const streamData = await client.getStream('username');
// Do stuff

This method can be used to get a specific UserData of a channel.

const userData = await client.getUser('username');
// Do stuff

This method can be used to add a channel to the list of channels to listen to.

client.addChannel('username');

This method can be used to remove a channel from the list of channels to listen to.

client.removeChannel('username');

This method can be used check if that channel is already in the list of channels to listen to.

client.includesChannel('username');

Types

// Example StreamData
StreamData {
  raw: {
    broadcaster_language: 'en',
    display_name: 'destiall',
    game_id: '509658',
    id: '142326619',
    is_live: true,
    tag_ids: [ '6ea6bca4-4712-4ab9-a906-e3336a9d8039' ],
    thumbnail_url: 'https://static-cdn.jtvnw.net/jtv_user_pictures/d555c2b8-fe43-4863-9e6f-78f5052eef41-profile_image-300x300.png',
    title: 'coding stream',
    started_at: '2020-12-22T08:29:53Z'
  },
  name: 'destiall',
  title: 'coding stream',
  game: 'Just Chatting',
  thumbnail: 'https://static-cdn.jtvnw.net/previews-ttv/live_user_destiall-320x180.jpg',
  profile: 'https://static-cdn.jtvnw.net/jtv_user_pictures/d555c2b8-fe43-4863-9e6f-78f5052eef41-profile_image-300x300.png',
  date: 2020-12-22T08:29:53.000Z,
  viewers: 1
}

// Example UserData
UserData {
  raw: {
    id: '47454325',
    login: 'dextimo',
    display_name: 'Dextimo',
    type: '',
    broadcaster_type: 'affiliate',
    description: "Hi i'm Dextimo, I love pandas, Formula 1 and  occasionally cod zombies.Btw tomatoes are disgusting :)",
    profile_image_url: 'https://static-cdn.jtvnw.net/jtv_user_pictures/8d9dd056-177f-43f2-966d-5c83d09a0e88-profile_image-300x300.png',
    offline_image_url: '',
    view_count: 977,
    created_at: '2013-08-11T20:17:02.073455Z'
  },
  name: 'dextimo',
  description: "Hi i'm Dextimo, I love pandas, Formula 1 and  occasionally cod zombies.Btw tomatoes are disgusting :)",
  id: '47454325',
  profile: 'https://static-cdn.jtvnw.net/jtv_user_pictures/8d9dd056-177f-43f2-966d-5c83d09a0e88-profile_image-300x300.png',
  views: 977,
  type: 'affiliate',
  created: 2013-08-11T20:17:02.073Z
}

twitchrequest's People

Contributors

destial avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bemw

twitchrequest's Issues

TypeError: Cannot read property 'id' of undefined

(node:1638) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of undefined
    at Client.<anonymous> (/home/runner/TwitchBot/node_modules/twitchrequest/index.js:615:65)

Getting this error upon running the code from the example.

const { Client } = require('twitchrequest');

const options = {
    channels: ["xxxxx"],
    client_id: "xxxxx",
    client_secret: "xxxxx",
    interval: 3
};

const client = new Client(options);

client.on('live', (data) => {
    console.log(`${data.name} is now live! Streaming ${data.title} on ${data.game}! Started at ${data.date}`);
});

TypeError: Cannot read property 'game_id' of undefined

I get an error message when I execute this exact code from your documentation.

const TwitchClientOptions = {
    channels: ['dracon', 'nilson1489', 'einfachflow'],
    client_id: "xxxxxxxxxxxxxxxxxx",
    client_secret: "xxxxxxxxxxxxxxxxxx",
    interval: 60
};
const client = new Client(TwitchClientOptions);

client.on('live', (streamData) => {
	console.log(streamData);
})
TypeError: Cannot read property 'game_id' of undefined
    at Client.<anonymous> (/root/twitchStreamBot/node_modules/twitchrequest/index.js:81:119)
    at step (/root/twitchStreamBot/node_modules/twitchrequest/index.js:46:23)
    at Object.next (/root/twitchStreamBot/node_modules/twitchrequest/index.js:27:53)
    at fulfilled (/root/twitchStreamBot/node_modules/twitchrequest/index.js:18:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

TypeError: TwitchRequest is not a constructor

Hi, I've followed the documentation as far as possible, but I keep getting the same error.
Maybe you can help me further.

const twitchClient = new TwitchRequest(TwitchClientOptions);
                     ^

TypeError: TwitchRequest is not a constructor
    at Object.<anonymous> (/root/twitchStreamBot/index.js:27:22)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

My code snippet.

const { TwitchRequest } = require("twitchrequest");
const TwitchClientOptions = {
    channels: [],
    client_id: "xxxxxxxxxxxxxxxxxxxx",
    client_secret: "xxxxxxxxxxxxxxxxxxxx",
    interval: 3
};
const twitchClient = new TwitchRequest(TwitchClientOptions);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.