Search code examples
github-apidiscord.js

Display info about GitHub commits


So, I have a discord bot, and one of the commands I'm hoping to use is to keep the user up to date on the latest update on a game I'm making on github, my question is, is there a way to grab the name and description of the latest commit?

I would assume it uses superagent but beyond that I'm lost.


Solution

  • I recommend you to use webhooks to post every commit to a specific channel.

    To do that, I've posted the tutorial from Discord here. (To get images by the tutorial, look at the Discord tutorial.

    1. Get the webhook URL for the server/channel you want to receive messages:

    In my server, I've created a text channel labeled #gitupdates. I want my repo updates to post messages here, so I'll grab the webhook URL for this channel:

    1. Add the webhook URL into your GitHub repo settings

    Choose the repository that you'd like to get updates from in your Discord server. Once you've selected the repo, go into the settings > webhooks menu:

    Sweet. Click the "Add webhook" button, and enter the Discord-generated URL in the "Payload URL" blank.

    To make the webhook display messages properly, it's really important that you append '/github' at the end of it.

    In addition to the URL, you have some more GitHub-specific options to choose from. For content type, stick with application/json. Discord's webhook format really likes JSON. In the next section, you can choose to customize what kind of events trigger webhook messages.

    Click the last "Add webhook" button beneath the event notifications customization option, and you're all set! Pushing any updates in the repo (including editing the readme file) will show up in your text channel:

    And you're all set!