Installation
Follow these steps to correctly install the script on your bot.
Installation steps
Section titled “Installation steps”-
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.
-
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
- Name (your application name, example:
- 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.envfile (twitchClientID & twitchClientSecret)
- Log in to the Twitch developer platform
-
Configure environment variables
Open the
.envfile 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 TwitchtwitchIDAccount: Twitch account ID (Leave empty, it will fill automatically)twitchChannelPostLive: ID of the channel where live notifications will be senttwitchRoleViewerID: 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.
-
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 folderutils/environment.js: into your utilities folder
Also copy the module indexing code into your main
index.jsfile. 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 theImages/folder, please add the stream start image (online.png) and stream end image (offline.png), preferably in 1920*1080 pixels. -
Update the database schema
Add the data model for retrieving Twitch live notifications to your
prisma/schema.prismafile and run the necessary migrations to apply the changes to your database. Run the following command:Terminal window npx prisma generatenpx prisma migrate dev --name add_twitch_notification -
Install dependencies
Make sure the required dependencies are installed by checking your
package.jsonand running:Terminal window npm install -
Restart the bot
Restart your bot so the script is loaded.
- In the
utils/twitch-notification.jsfile, you can modify the time in minutes for checking before a stream is marked as ended. Change theattemptReconnectMaxvariable which is currently set to 10 minutes.