Skip to content

Instantly share code, notes, and snippets.

@smiley
Last active July 19, 2024 23:33
Show Gist options
  • Save smiley/78c1c2a57d17a179a978a1438b389710 to your computer and use it in GitHub Desktop.
Save smiley/78c1c2a57d17a179a978a1438b389710 to your computer and use it in GitHub Desktop.
How to make an automatic "stream's live" notification for your Discord server

Making an automatic Twitch -> Discord notification (using IFTTT)

So you went live and you want everyone to know. Here's how you do it:

Part 1 - Register on IFTTT

Go to https://ifttt.com/ and create an account (if you don't already have one)

Part 2 - Make a Discord Webhook

  • Find the Discord channel in which you would like to send Tweets.
  • In the settings for that channel, find the Webhooks option and create a new webhook. Note: This URL should be kept private. It allows anyone to write messages to that specific channel using that specific URL. Keep it safe! WebhookDiscord
  • Name the webhook however you like and feel free to change the generic profile picture. I chose this icon as it fits the circle nicely.
  • Copy the URL somewhere and keep it handy for the next step.

Part 3 - Create a new IFTTT applet/recipe

  1. Go here to create a new "Applet"
  2. Click the big blue "[+] This" and choose "Twitch" (use the search bar to find it quickly)
  3. Connect your account if necessary.
  4. Choose "New stream started by you" (it should be the 2nd option from the left)
  5. Click the big blue "[+] That" and choose "Webhooks"
  6. Choose "Make a web request" (it should be the only option)
  7. Fill in the following details:

    URL: [your URL from "part 2" above] Method: POST Content type: application/json Body: [see the snippet below]

  8. Click "Create Action"
  9. Done!

Snippet for "Body"

Webhooks are super-customizable and allow you to make pretty well-detailed visuals. However, their format is also somewhat complex to get right without extensive testing, so here's a template which would be useful to most people:

{
  "content": "{{ChannelName}} went live on Twitch",
  "embeds": [{
    "title": "{{ChannelUrl}}",
    "url": "{{ChannelUrl}}",
    "color": 6570404,
    "footer": {
      "text": "{{CreatedAt}}"
    },
    "image": {
      "url": "{{StreamPreview}}"
    },
    "author": {
      "name": "{{ChannelName}} is now streaming"
    },
    "fields": [
      {
        "name": "Playing",
        "value": "{{Game}}",
        "inline": true
      },
      {
        "name": "Started at (streamer timezone)",
        "value": "{{CreatedAt}}",
        "inline": true
      }
    ]
  }]
}

This snippet produces this snippet: (for the channel "xQcow"): Example using xQcow's channel

Custom message

If you'd like to customize the message text -- "xqcow has gone live on Twitch!" -- change the content attribute:

{
  "content": "{{ChannelName}} has gone live on Twitch!",
  "embeds": [{

Show your Twitch profile picture in the embed (advanced)

If you'd like to show your Twitch profile picture in the box:

  1. Go to Twitch
  2. Right-click your profile picture in the top-right:

User area on Twitch.tv

  1. Click "Copy image address"
  2. Paste that address into this blob instead of <IMAGE_URL>:
"thumbnail": {
  "url": "<IMAGE_URL>"
},
  1. Paste that blob below the image area in the main blob, so that part would change from this:
    "footer": {
      "text": "{{CreatedAt}}"
    },
    "image": {
      "url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_{{ChannelName}}-1280x720.jpg"
    },
    "author": {
      "name": "{{ChannelName}} is now streaming!"
    },

To this:

    "footer": {
      "text": "{{CreatedAt}}"
    },
    "image": {
      "url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_{{ChannelName}}-1280x720.jpg"
    },
    "thumbnail": {
      "url": "<IMAGE_URL>"
    },
    "author": {
      "name": "{{ChannelName}} is now streaming!"
    },

Note: The image address you just used for your Twitch profile picture may stop working if you change your picture. I'm not sure how Twitch manages those.

Credits

@DeFlanko
Copy link

DeFlanko commented Jun 25, 2021 via email

@Grizzly1987
Copy link

Hello, thank you very much for this great tutorial;). But I have one more question. Is there a possibility to include a query? The following procedure. On our Discord server there is the role @streamer, everyone who has this role is linked to his or her Twitch channel in our bot. Now the bot should only write in the channel (live status) if this streamer only plays a certain game (from our GTA RP server). If he plays other games, no live notification should be posted. Warm greetings

@wild-eragon
Copy link

Hey there, good job with it! By chance, would you have any code for this using a RSS feed?

@Jankeczek
Copy link

it works really well, thanks... BUT uhh do ya'll know is there an option for it to not be english and not use A.M and P.M stuff?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment