How to Connect Discord and GitHub Using Webhooks

How to Connect Discord and GitHub Using Webhooks

Connecting Discord and GitHub using webhooks allows you to automatically send GitHub updates to a Discord channel. Here’s how you can set it up:

Step 1: Create a Discord Webhook

  1. Open Discord and go to the server where you want to send GitHub updates.

  2. Navigate to the Channel Settings:

    • Right-click the channel where you want the updates to appear.

    • Select Edit Channel.

  3. Create Webhook:

    • Go to the Integrations tab.

    • Click Create Webhook.

    • Fill in the webhook details:

      • Name: Give your webhook a name.

      • Channel: Choose the channel where updates will be posted.

      • Avatar: Optionally, you can upload an avatar for the webhook.

    • Click Copy Webhook URL to copy the URL. This URL is crucial for connecting GitHub.

    • Save the webhook.

Step 2: Set Up the GitHub Webhook

  1. Go to your GitHub repository: Open the repository you want to connect to Discord.

  2. Navigate to Settings:

    • Click on the Settings tab of your repository.
  3. Create Webhook:

    • In the left sidebar, click on Webhooks.

    • Click Add webhook.

  4. Configure the Webhook:

    • Payload URL: Paste the Discord webhook URL you copied earlier.

    • Content type: Select application/json.

    • Secret: (Optional) You can add a secret for extra security, but it is not necessary for basic setups.

    • Events: Select individual events you want to send to Discord, or choose Just the push event or Send me everything.

    • Click Add webhook to save.

Example Payload Customization

You can customize the payload sent to Discord to format the messages in a more readable way. However, GitHub’s default webhook payloads are usually sufficient for most notifications.

Verifying the Setup

To ensure the setup works correctly, perform an action in your GitHub repository that triggers the webhook, such as pushing a commit or opening an issue. You should see the corresponding message appear in the Discord channel.

Troubleshooting

  • Ensure that the webhook URL is correctly copied.

  • Check that the webhook events selected in GitHub correspond to actions you are performing.

  • Ensure the Discord bot (webhook) has the necessary permissions to post messages in the channel.

By following these steps, you should have GitHub updates being posted to your Discord channel automatically. This integration helps in keeping your team informed about the latest changes without manually sharing updates.