iSlammedMyKindle / twitchToDiscordBot

Cross-platform messaging interface between discord and twitch chats
1 stars 2 forks source link

Twitch To Discord

Welecome! The goal of this bot is to combine the abilities of Discord and Twitch, and allow both chats to communicate between eachother.

This file is designed to provided an overview of how to get the bot setup yourself on a custom environment.

Setup - Twitch side

  1. To start on the Twitch side, first navigate to the Twitch console
  2. Click on the "Applications" tab at the top.
  3. From here, you would click "Register Your application". It needs a name that hasn't been used on a bot before.
  4. After the bot is created, go ahead and click "manage" on the new application, you will see options for Client ID and Client Secret. Create the the secret, and store it for later. Client ID will always be the same, but save this as well. These items in particular should be stored in config.json as CLIENT_ID and CLIENT_SECRET, under twitch
  5. Set ACCOUNT_USERNAME to your account's Twitch username, and add the same username to the CHANNELS

These new credentials will be there to help you authenticate this bot to use your user. This will be done in your web browser. When finished, the bot should communicate out of the user that authenticated it (e.g iSlammedMyKindle would be used to send messages, but internally, the bot can detect if it was sent via itself or other means besides your own keyboard input.)

There's also one channel you need to insert as well (CHANNELS) - the bot only reads the first one, so in the first array index, pop in your username or whatever user's channel name to listen to that one.

External server

If you intend on deploying this on an external server, you will need to change the address found in config.json -> REDIRECT_URI. Change it to the ip or domain name of the server, and redirects should work accordingly. (note that in this early version, the port is hard-coded to 3000; this will be used to deploy a temporary http server. Keep this in mind as providers like google cloud require that you expose ports before using them)

Another note is that if you try to deploy on a web server outside your local machine; auto-opening the browser is not supported. You will need to manually click on the link that is generated in the terminal to fully launch it. After launching the link, the process should be back to the flow as described above.

Setup - discord side

  1. Visit the Discord developer portal; you'll find a button that says "new application", so click that
  2. Set the name to whatever you like
  3. navigate to your bot, click "Bot", then create the bot using the discord prompts
  4. The main item you need here is the discord token, which will go into config.json -> T2D_DISCORD_TOKEN
  5. In the oAuth2 menu, select URL Generator; check bot, then in the second box, check "Manage messages", "Send Message", and "Read Messages"
  6. copy the link and paste it into your browser; from here you should be able to add the bot to your test server. (Save this link for later, you'll need it to add it to other places when required)

To prepend an emoji to the sent message, follow these steps:

  1. Visit the Discord developer portal, select your application and go to the Emojis section
  2. Upload your emoji by clicking the Upload Emoji button
  3. After upload, copy the emoji name and ID and paste it in the configuration:
"discord":{
    // Rest of the file
    "EMOJI_NAME": "your_emoji_name_here",
    "EMOJI_ID": "your_emoji_id_here"
},

If not provided, an emoji won't be displayed, just the username + message.

Setting up a Discord channel

On your Discord server, the channel that will reflects Twitch chat needs to have permissions disabled on it. Twitch is directly based on an IRC standard, which means things like threads are not going to be supported.

Create the channel, and then copy it's Discord ID (enable developer settings in your personal Discord settings to make this work.) You can also find the Discord ID in the URL of your browser if Discord is being used there (it will be the last set of numbers in the link). Place the channel ID inside config.js -> T2D_DISCORD_CHANNEL.

T2D_DEV_SAVE_TOKEN

You'll need this setting toggled to true if you are just developing the bot. Twitch only offers up to 50 tokens at a given time, so this will prevent you from maxing that out quickly!

Launching the bot

Run the build script with npm run build, then run npm run start and a link should show up in the terminal (if you're on localhost/desktop, a browser window should pop up); it will make you authenticate with Twitch. Once that's finished, the bot should be up and running! If you set T2D_DEV_SAVE_TOKEN to true, the token that was just created will be saved to a file for when you need to relaunch the bot. If this token expires, you'll need to delete the file to start over. (for now)

Authorization page customization

At this current point in time, by setting the AUTH_PAGE_PATH in config.json, or T2D_AUTH_PAGE_PATH in your enviorment variables, you are able to directly change the page which is shown once you authenticate. We currently have a default page which is used if you do not wish to pass one/create one.

Subs, follows, bits, and channel points

twitchToDiscord was designed to be run by a separate user other than the broadcaster. However, the four above events can only be subscribed to by the broadcaster user. To get around this, the project makes use of twitchListenerCore, a separate application.

This will send these events directly to discord without creating another bot that uses both twitch and discord apis together.

The following flags are accepted for the config or environment variables:

Launching with environment variables

Environment variables will have the same syntax for the most part just like in the config.json. However, there are some main differences when applying the https env's - which are listed below:

Credits