Discord Changelog Bot


In the #changelog channel in the Blendo Games Discord, it displays this:

It’s a live log of my source control changelog messages for Skin Deep. That means: whenever I check anything into source control, my changelog note gets displayed here.

I made this for a few reasons:

How it works

Whenever I check anything in, my source control client runs a small program to post a message to Discord. Done!

Bot code

My code to post Discord messages is one C# file. Here’s the entire source code for it:

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        private static string discordURL = "YOUR_DISCORD_WEBHOOK";
        private static readonly HttpClient client = new HttpClient();

        static void Main(string[] args)
        {
            if (args == null) //if no argument, then exit.
                return;

            if (args.Length <= 0) //if no argument, then exit.
                return;

            string changelog = args[0];

            if (string.IsNullOrWhiteSpace(changelog)) //if argument is empty, then exit.
                return;

            //We have a valid message. Send the message to discord.
            DiscordMsg discordMessage = new DiscordMsg(changelog);
            var discordMessageJSON = JsonConvert.SerializeObject(discordMessage, Formatting.Indented);
            var resp = client.PostAsync(discordURL, new StringContent(discordMessageJSON, Encoding.UTF8, "application/json")).Result;
        }
    }

    public class DiscordMsg
    {
        [JsonProperty("content")]
        public string content { get; set; }

        public DiscordMsg(string message)
        {
            content = message;
        }
    }
}

The program generates an .exe file. When you run the .exe, any included arguments are sent as the Discord message.

Then, hook up your source control client to run this .exe file.

Source control client

Now you need to tell your source control client, “whenever I check anything in, run the Bot .exe file.” I use TortoiseSVN as my source control client, but this can be adapted to whatever client you use.

First go to: TortoiseSVN > Settings > Hook Scripts > Add…

This pops up a dialogue box. Fill it in with the appropriate info:

And that’s it. Now, whenever you check anything in, it will propogate your changelog message to your Discord. Enjoy!