Skip to content

Instantly share code, notes, and snippets.

@jagrosh
Last active September 16, 2024 13:49
Show Gist options
  • Save jagrosh/5b1761213e33fc5b54ec7f6379034a22 to your computer and use it in GitHub Desktop.
Save jagrosh/5b1761213e33fc5b54ec7f6379034a22 to your computer and use it in GitHub Desktop.
Simple Github -> Discord webhook

Step 1 - Make a Discord Webhook

  1. Find the Discord channel in which you would like to send commits and other updates

  2. In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe! WebhookDiscord

Step 2 - Set up the webhook on Github

  1. Navigate to your repository on Github, and open the Settings Settings

  2. Select Add Webhook Add

  3. Paste in the webhook url and append /github to the end. Select "Send me everything", set the type to application/json, and then Add Webhook WebhookSettings

  4. Test it by updating something or starring the repository! If it works, you're all set! Star

@fiizzy
Copy link

fiizzy commented Jun 20, 2022

Heyy guys, here is my issue:

All of a sudden my Github webhook has stopped firing events. In the recent deliveries tab, it doesn't even show that an event was triggered by github itself, when in fact I have made a pus/commit etc.

It seem more like a github issue, as my netlify has also stopped automatically building. So I'm guessing GH isn't sending any POST req. from my organization.

Don't know how or why that is happening.
Any suggestions would be appreciated.

@jonesXYZ
Copy link

same here.

@fiizzy
Copy link

fiizzy commented Jun 20, 2022

Heyy @jonesXYZ , I just tried a push again this evening [ after about 24hrs since I noticed ] and the webhook is once again sending to the discord channel and my netlify builds are automatically deploying based on my GH pushes/PRs.

So, my best guess is that it was a github thingy.
Have you tried yours recently to see if it works ?

@maxmandia
Copy link

Does this work with private repos?

@fiizzy
Copy link

fiizzy commented Jul 6, 2022

@maxmandia Yes, it works on private repos.

@SparkRS
Copy link

SparkRS commented Jul 6, 2022

very gud!
image

@aallbrig
Copy link

aallbrig commented Jul 7, 2022

I was able to successfully add these webhooks using the Github CLI. Here is a slimmed down version of code. Hope some find this helpful. Cheers!

# raw copy of discord channel webhook URL
discord_webhook=""
url="${discord_webhook}/github"
# your target github org
org=""
# your target github org repo
repo=""

gh api /repos/"${org}"/"${repo}"/hooks \
  --input - <<< "{
  \"name\": \"web\",
  \"active\": true,
  \"events\": [
    \"*\"
  ],
  \"config\": {
    \"url\": \"${url}\",
    \"content_type\": \"json\"
  }
}"

@Maxime66410
Copy link

is don't work for me.
image
image

@nitrodynamite18
Copy link

Thank you so much, this worked perfectly!

@Maxime66410
Copy link

is don't work for me. image image

Correction, so that it works despite the tutorial followed and you still have a 400 error.

Just go to "Recent Deliveries" and resend the request, after that it should work.

@yeste-rge
Copy link

yeste-rge commented Jul 31, 2022 via email

@ishini-peiris
Copy link

Can we duplicate the same webhook on different repositories?

@ABUCKY0
Copy link

ABUCKY0 commented Aug 6, 2022

Probabaly

Can we duplicate the same webhook on different repositories?

@natereprogle
Copy link

Can we duplicate the same webhook on different repositories?

Webhooks are just a way to deliver messages. You can use the same webhook on multiple different repos, but they will all deliver to the same Discord channel since Webhooks are channel specific afaik.

@Dyplay
Copy link

Dyplay commented Aug 25, 2022

thanks it worked!

@Dyplay
Copy link

Dyplay commented Aug 25, 2022

thanks it worked!

@SciTechEnthusiast
Copy link

SciTechEnthusiast commented Aug 29, 2022

same worked for me after redeliver till then it was showing error.

In the webhook url add /github suffix

select application/json

Also you can choose what updates you want.

image

if you are also getting 400 just go to recent deliveries and rerun
image

and here it is working

image

@natereprogle
Copy link

same worked for me after redeliver till then it was showing error.

In the webhook url add /github suffix

select application/json

Also you can choose what updates you want.

image

if you are also getting 400 just go to recent deliveries and rerun image

and here it is working

image

That was step 3 of the original gist, complete with screenshots…

@danieluac
Copy link

Thanks it worked for me too 🎉

@Brian-Pob
Copy link

Worked for me with no modifications. Thanks for the guide.

@Ahmed3457
Copy link

Works fine thank you so much

@zocker-160
Copy link

thank you, worked perfectly

@r-coh
Copy link

r-coh commented Oct 13, 2022

Gracias.

@Kipjr
Copy link

Kipjr commented Oct 15, 2022

image
I only received this after configuring the webhook. Any idea how to fix it?

@Kipjr
Copy link

Kipjr commented Oct 15, 2022

image
Fixed using Discord settings

@StephenHodgson
Copy link

Anyone know how to setup for private channel?

@foxt
Copy link

foxt commented Nov 15, 2022

@StephenHodgson setting up a webhook for a private channel is the same as setting up for a public 😋

@StephenHodgson
Copy link

I figured out what I did wrong. Needed to add /github to the end of my webhook url

@Zement
Copy link

Zement commented Nov 19, 2022

It's been working great for a long time! 🙂
Question: Does it also work for an entire organization and all repos from that org, or would I have to do it separately?

@TheJeterLP
Copy link

It's been working great for a long time! 🙂 Question: Does it also work for an entire organization and all repos from that org, or would I have to do it separately?

I tried to do it for the entire organization, github sends the post events out, but nothing happens in the desired channel.

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