Skip to content

Installation

Follow these steps to correctly install the script on your bot.

  1. Download the module & unzip the folder

    Retrieve the module folder (usually in .zip or .rar format) from the official source. Use a tool like WinRAR or 7-Zip to extract the script folder on your computer.

  2. Create your Twitch API keys

    • Log in to the Twitch developer platform
      Go to: Developer to log in or create an account to access the developer console.

    • Access the developer console
      Once logged in, go to the applications console: Console

    • Create your application
      Click on “Create Application” or go to this link: Create app
      Fill in the following fields:
      • Name (your application name, example: BotTwitch)
      • OAuth redirect URL: http://localhost
      • Category: Application Integration
      • Client Type: Confidential

    • Retrieve the keys
      Once the application is created, click “Manage” next to your application.
      Copy your Client ID
      Click on “New Secret” to generate your Client Secret and copy it
      In the next step, we will need to encode them in the .env file (twitchClientID & twitchClientSecret)

  3. Configure environment variables

    Open the .env file provided with the script and add & modify the environment variables needed for the module to work correctly.

    • twitchClientID : The Twitch API client ID key (See step 2)
    • twitchClientSecret : The Twitch API secret key (See step 2)
    • twitchUserAccount : ⚠️ The exact username of the streamer on Twitch
    • twitchIDAccount : Twitch account ID (Leave empty, it will fill automatically)
    • twitchChannelPostLive : ID of the channel where live notifications will be sent
    • twitchRoleViewerID : ID of the viewer role (Usually the member role to notify the entire server or a custom role you created so members can choose this role to be notified of a new stream!)
    • twitchChannelFollowerID: ID of the voice channel that will be updated with the number of followers. Leave it blank if you do not want to update the voice channel.
  4. Copy/move the files/code into your project

    Copy the following files into the appropriate folder(s) of your Discord bot project:

    • utils/twitch-notification.js : into your utilities folder
    • utils/environment.js : into your utilities folder

    Also copy the module indexing code into your main index.js file. In this file, we added Prisma directly linked to the “client” object, add this code to yours or adjust it according to how you use Prisma.

    ❗ Create an Images/screen-live/ folder, it will be used as a buffer for image storage. Once the stream is finished, the folder content will be deleted. In the Images/ folder, please add the stream start image (online.png) and stream end image (offline.png), preferably in 1920*1080 pixels.

  5. Update the database schema

    Add the data model for retrieving Twitch live notifications to your prisma/schema.prisma file and run the necessary migrations to apply the changes to your database. Run the following command:

    Terminal window
    npx prisma generate
    npx prisma migrate dev --name add_twitch_notification
  6. Install dependencies

    Make sure the required dependencies are installed by checking your package.json and running:

    Terminal window
    npm install
  7. Restart the bot

    Restart your bot so the script is loaded.

  • In the utils/twitch-notification.js file, you can modify the time in minutes for checking before a stream is marked as ended. Change the attemptReconnectMax variable which is currently set to 10 minutes.