Page cover image

Discord

To use the embedded discord client. Register the hook URI at start, then call anywhere else

Code

PerigeeApplication.ApplicationNoInit("Discord",  (c) => {

    //Register once
    AlertManager.RegisterDiscordWebhook("bot", "WEBHOOKURI");

    //Call anywhere else
    int IssueCount = 0;
    AlertManager.Webhook_Discord("bot", new DiscordMessage()
    {
        Embeds = new List<DiscordEmbed>() {
            new DiscordEmbed() {
                Title = $"My awesome discord enabled app {(IssueCount > 0 ? "failed" : "completed")}",
                Description = IssueCount > 0 ? "Issues exist, please check log." : "Everything completed as expected",
                Color = IssueCount > 0 ? System.Drawing.Color.Yellow : System.Drawing.Color.Green,
                Fields = new List<EmbedField> {

                    new EmbedField() { InLine = true, Name = "Server", Value = "MyServer"},
                    new EmbedField() { InLine = true, Name = "Issue Count", Value =  IssueCount.ToString() },
                    new EmbedField() { InLine = false, Name = "Location", Value = Directory.GetCurrentDirectory() },
                }
            }
        }
    });

});

There's also a builder method is you're creating the same information, it makes the creation a bit more compact and without having to remember the nested syntax:

AlertManager.Webhook_Discord("bot", DiscordMessage.Builder(
        $"My awesome discord enabled app {(IssueCount > 0 ? "failed" : "completed")}",
        IssueCount > 0 ? "Issues exist, please check log." : "Everything completed as expected", null,
        IssueCount > 0 ? System.Drawing.Color.Yellow : System.Drawing.Color.Green,
        EmbedField.Builder("Server", "MyServer"),
        EmbedField.Builder("Issue Count", IssueCount.ToString()),
        EmbedField.Builder("Location", Directory.GetCurrentDirectory())));

Last updated