Siddhart / Twitch-Discord-Bot

Discord bot that uses the Twitch API to send a message whenever a streamer goes live.
MIT License
50 stars 19 forks source link
discord discord-bot discord-js nodejs notifications twitch twitch-api

Twitch Discord Bot

This Discord bot will automatically send a message and tag the assigned role whenever a streamer went live. The notifications will update every 10 minutes(default) while the streamer is live.

How does it work?

This Discord bot uses The Official Twitch Api. You will be able to assign unlimited streamers to the bot. The bot uses the api to fetch the channel data to see if the streamer is live. If the streamer is live it will send a message in the assigned channel and it will also tag the assigned role. You will be able to choose the update time. If the streamer is still live the bot will update the message after X amount of time (default 10 minutes).

Embed Preview

Installation

First you will have to clone the project.

$ git clone https://github.com/Siddhart/Twitch-Discord-Bot

After that open the config.json file

{
    "DiscordServerId": "DISCORD_GUILD_ID(REQUIRED)",
    "token": "DISCORD_API_BOT_TOKEN(REQUIRED)",
    "twitch_clientID": "TWITCH_API_CLIENT_ID(REQUIRED)",
    "twitch_secret": "TWITCH_API_SECRET(REQUIRED)",
    "cron": "*/10 * * * * *",
    "channelID": "CHANNELD_ID(REQUIRED)",
    "roleID": "ROLE_ID(NOT REQUIRED)",
    "channels": [
        {
            "ChannelName": "STREAMER_NAME(REQUIRED)",
            "DiscordServer": "DISCORD_SERVER_INVITE_URL(NOT REQUIRED)",
            "twitch_stream_id": "",
            "discord_message_id": ""
        }
    ],
    "authToken": ""
}

Edit Config.json

NOTE: Do NOT add anything in the fields that are already empty. These fields will automatically update. Some of values in the config.json template have "(NOT REQUIRED)" in it. If you are not using this replace it with an empty string. "DISCORD_SERVER_INVITE_URL(NOT REQUIRED)" --> ""

Add streamers

In the config.json there is a channels array. If you want to add streamers you just add new objects to this array.

{
   "ChannelName": "STREAMER_NAME(REQUIRED)",
   "DiscordServer": "DISCORD_SERVER_INVITE_URL(NOT REQUIRED)",
   "twitch_stream_id": "",
   "discord_message_id": ""
}

An array with multiple streamers will look something like this:

{
   "ChannelName": "STREAMER1",
   "DiscordServer": "Some Discord invite url here",
   "twitch_stream_id": "",
   "discord_message_id": ""
},
{
   "ChannelName": "STREAMER2",
   "DiscordServer": "",
   "twitch_stream_id": "",
   "discord_message_id": ""
}

Dependencies

In order for the bot to work properly you will have to install the node packages discord.js, cron and request. Use the following command to install the dependencies.

$ npm install discord.js cron request

Run the bot

After you updated the config.json and installed the dependencies you can run the final command. Use the command in the same directory as the index.js file.

$ node index.js

Congratulations! You have successfully setup the bot. If there are any errors please send me a dm on Discord siddhartt