Skip to content

Instantly share code, notes, and snippets.

@jagrosh
Last active March 24, 2024 19:49
Star You must be signed in to star a gist
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

@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.

@brndto
Copy link

brndto commented Dec 22, 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?

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

Did you check the errors in the Github webhook's recent deliveries area? I accidentally forgot to change it to the content type application/json when I set mine up but it seems to work fine now.

@TheJeterLP
Copy link

Did you check the errors in the Github webhook's recent deliveries area? I accidentally forgot to change it to the content type application/json when I set mine up but it seems to work fine now.

Yes I did, they all get delivered. It did work, but only new commits got displayed in discord. Nothing else, altho I choose to deliver everything.

@TheJeterLP
Copy link

Must be an issue on discords side...

@RealDogDad
Copy link

Preesh, this is clutch

@husamhabib
Copy link

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\"
  }
}"

where to write this ?

@aallbrig
Copy link

@husamhabib Into a terminal of some kind. You have to have the GitHub CLI installed. If you're on windows you may want to use git bash?

Props to seeing my comment. I've been seeing the chatter but you're the first person to see the CLI stuff..!

@tungdt-90
Copy link

It works for a single repo, but when I add it to the organization's webhook, Discord will not post any message.

@Vedsaga
Copy link

Vedsaga commented Feb 9, 2023

It works for a single repo, but when I add it to the organization's webhook, Discord will not post any message.

exactly, didn't working for me also... just seeing what is going wrong...

@tungdt-90
Copy link

@Vedsaga Actually, after a while, it kind of works for me. My discord server got updates from some repos, but some other repos simply stay silent. I'm not sure what the cause was, but in the meantime, I created several webhooks for different repos.

@Benjamin1021523
Copy link

image
It works! thx

@Vedsaga
Copy link

Vedsaga commented Mar 25, 2023

Yes it dose work after like some time...

@jchen42703
Copy link

Works for me perfectly as of 4/30/23

@awesome24712
Copy link

I tried this, Github shows the requests going out with 204 responses coming back, but nothing appears in discord?

@rabeehebrahim
Copy link

Thanks. I love this feature.

@kpebron
Copy link

kpebron commented Aug 4, 2023

is it possible to ping/mention/notify everyone or certain people using the webhook?

@PanoptesDreams
Copy link

I tried this, Github shows the requests going out with 204 responses coming back, but nothing appears in discord?

Me too, any help anyone?

@makeryoungjin
Copy link

I tried this, Github shows the requests going out with 204 responses coming back, but nothing appears in discord?

same

@ItzKeyYT
Copy link

ItzKeyYT commented Aug 27, 2023

I've found a solution, if there's still X's on your webhook, just straight up delete that and create a new one and Make sure to add /github at the discord webhook after you pasted it, hope this helps!

@PanoptesDreams
Copy link

I've found a solution, if there's still X's on your webhook, just straight up delete that and create a new one and Make sure to add /github at the discord webhook after you pasted it, hope this helps!

I don't know why this is correct, but it worked after deleting the Hook and readding it, it just worked this time.

Can some people smarter than us actually find out what's broken so we can properly document or fix this?

@jexroid
Copy link

jexroid commented Sep 3, 2023

thanks. it works just fine

@lucas-av7
Copy link

I enabled the issues section but Discord only sends a message when an issue is closed.

it does not send a message when these other events occur (Altouhg discord response is success):

Screenshot 2023-09-06 at 12 07 34

@kartikeyaggarwal
Copy link

Is there any way I also get diff data in webhook like in gitlab email notification

@RocketRacer
Copy link

Delivery is successful, I get 204 and nothing happens in the channel itself. Something must have gone wrong on Discord's side over last couple of months, what a shame.

@mrgoonie
Copy link

mrgoonie commented Oct 4, 2023

I've found a solution, if there's still X's on your webhook, just straight up delete that and create a new one and Make sure to add /github at the discord webhook after you pasted it, hope this helps!

This works! If you already add failed webhook before, you also need to delete it and add it again with /github at the end of the URL (another note is Content-Type must be application/json)

Cheers!

@joshytaco
Copy link

joshytaco commented Oct 8, 2023

I've found a solution, if there's still X's on your webhook, just straight up delete that and create a new one and Make sure to add /github at the discord webhook after you pasted it, hope this helps!

What do you mean by this? Does the webhook not work if there are Xs in the webhook url? What an odd bug.

I'm getting the same issue as others in this thread, created a webhook url to post to a discord channel and GitHub says that the request was sent with a 204 response, but nothing is appearing in the discord channel.

EDIT: fwiw, the test deploys on github's end don't work. you'll need to test with a real action in the repo (push to branch, etc)

@Seavens
Copy link

Seavens commented Oct 12, 2023

Is it possible to send the whole commit message rather then the first few words?

@Milkywayrules
Copy link

ah, thank you, dude!

@Taureon
Copy link

Taureon commented Nov 15, 2023

please add a red box around the "application/json" part of the image!

@KalaniNorman24
Copy link

How do I make the webhook push text documents of updates?

@lukehinds
Copy link

As with others, the webhook status is green (204), but nothing gets posted to discord.

@neoneye
Copy link

neoneye commented Jan 3, 2024

Same issue here. The webhook works when installed on specific repos. However the webhook doesn't work for the organization.

Any idea how to get the webhook work for the organization?

@romanr
Copy link

romanr commented Jan 9, 2024

Got it working:

  1. delete hook
  2. create new hook
  3. add /github at the end,
  4. select content type to application/json

@jhelmink
Copy link

jhelmink commented Jan 11, 2024

There is an official list of supported events from Discord, and no plans to add more;

discord/discord-api-docs#6203 (comment)

If your event is not on the list, you'll still get a 204, but nothing will come through.

@arbitrarily
Copy link

Got it working:

1. delete hook

2. create new hook

3. add /github at the end,

4. select content type to `application/json`

my man <3 +1

@Benualdo
Copy link

Benualdo commented Mar 4, 2024

Is it possible to send the whole commit message rather then the first few words?

+1

Displaying the name of the target being build would be nice too (I have 4 .yml workflows and they all just display "build success on master").

@Shreyan1
Copy link

I've found a solution, if there's still X's on your webhook, just straight up delete that and create a new one and Make sure to add /github at the discord webhook after you pasted it, hope this helps!

This works. This is the only thing that works.

Add the /github at the end of the Webhook URL.

@haddercone
Copy link

I'm trying to implement the same. But it is more specific. I looked at the GitHub events, they are more generic and not action specific.
E.g I want to receive a message only when a PR is merged or a certain comment is added to the PR.
Is there a way yo to customise this behaviour?

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