Giter VIP home page Giter VIP logo

discord-webhook-client's Introduction

Discord Webhook Client

AppVayor - Build status NuGet NuGet

Simple .NET client to send Discord (https://discordapp.com/) messages using a webhook.

Reference documentation for creating this client: Discord Webhooks Guide and Discord Developer Portal.

Target

.NET Standard 2.0+

For more information about suported versions visit https://docs.microsoft.com/pt-br/dotnet/standard/net-standard

Installation

NuGet

Install-Package discord-webhook-client

.NET CLI

dotnet add package discord-webhook-client

Sending a message...

Sending a message is very simple!

// Add reference to namespace JNogueira.Discord.Webhook.Client
using JNogueira.Discord.Webhook.Client;

// Create an instance of the class DiscordWebhookClient with your Discord webhook URL.
var client = new DiscordWebhookClient("Your Discord webhook URL here!");

// Create your DiscordMessage with all parameters of your message.
var message = new DiscordMessage(
    "Discord Webhook Client sent this message! " + DiscordEmoji.Grinning,
    username: "Username",
    avatarUrl: "https://avatars3.githubusercontent.com/u/24236993?s=460&v=4",
    tts: false,
    embeds: new[]
    {
        new DiscordMessageEmbed(
            "Embed title " + DiscordEmoji.Thumbsup,
            color: 0,
            author: new DiscordMessageEmbedAuthor("Embed 1 author name"),
            url: "https://github.com/jlnpinheiro/discord-webhook-client/",
            description: "This is a embed description.",
            fields: new[]
            {
                new DiscordMessageEmbedField("Field 1 name", "Field 1 value"),
                new DiscordMessageEmbedField("Field 2 name", "Field 2 value")
            },
            thumbnail: new DiscordMessageEmbedThumbnail("https://avatars3.githubusercontent.com/u/24236993?s=460&v=4"),
            image: new DiscordMessageEmbedImage("https://avatars3.githubusercontent.com/u/24236993?s=460&v=4"),
            footer: new DiscordMessageEmbedFooter("This is a embed footer text", "https://avatars3.githubusercontent.com/u/24236993?s=460&v=4")
        )
    }
);

// Send the message!
await client.SendToDiscord(message);

Look at to your Discord channel...your message is there!

A messagem in your Discord channel

Sending a message with file attachments

var message = new DiscordMessage(
    ...
);

var file1 = new DiscordFile("test1.txt", Encoding.UTF8.GetBytes("This is the first file."));

var file2 = new DiscordFile("test2.txt", Encoding.UTF8.GetBytes("This is the secound file."));

await client.SendToDiscord(message, new[] { file1, file2 });

Send message as file attachment on exception

When an exception is throwing on sending the message, a new message can be sent to Discord with attachments containing message data and exception information.

var message = new DiscordMessage(
    content: new string('0', 7000), // <-- The content length limit is 2000 characters => Exception is throwing.
    ...
);

await _client.SendToDiscord(message, true);

A messagem in your Discord channel

discord-webhook-client's People

Contributors

cxnky avatar dependabot[bot] avatar jlnpinheiro avatar ofirvalla avatar xpierroz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discord-webhook-client's Issues

How can I split this into to webhooks

``public` async void RoundBtn1_Click(object sender, EventArgs e)
{
MessageBox.Show("Your ticket has been sent!" + Environment.NewLine + Environment.NewLine + "Please allow up to 24 hours for our staff to reply to your message and please make sure your discord dms are open.");

        // Create an instance of the class DiscordWebhookClient with your Discord webhook URL.
        var client = new JNogueira.Discord.Webhook.Client.DiscordWebhookClient("https://discord.com/api/webhooks/");
    // Create your DiscordMessage with all parameters of your message.
    var message = new DiscordMessage(
        "New Ticket",
        username: "//",
        avatarUrl: "//",
        tts: false,
        embeds: new[]
    {
                new DiscordMessageEmbed(
        "User Information",
        color: 3843043,
        author: new DiscordMessageEmbedAuthor("//"),
        url: "//",
        description: "Coded By: //",
        fields: new[]
        {
            new DiscordMessageEmbedField("User:", ResponseInformation.loginresponse.UserName),
            new DiscordMessageEmbedField("Email:", ResponseInformation.loginresponse.Email),
            new DiscordMessageEmbedField("//:", //()),
            new DiscordMessageEmbedField("Discord :", tbDiscord.Text),
            new DiscordMessageEmbedField("Subject:", cbSubject.Text),
            new DiscordMessageEmbedField("Message:", tbMessage.Text),
            new DiscordMessageEmbedField("Version: 2.3")

        },

        footer: new DiscordMessageEmbedFooter("//")


            )

        }

    );
      
   
       await client.SendToDiscord(message);
        this.Close();
    
    }

``
all the // means the information I have cut out

if i would have to split it up then i would like to make this part of the 1st webhook
new DiscordMessageEmbedField("User:", ResponseInformation.loginresponse.UserName), new DiscordMessageEmbedField("Email:", ResponseInformation.loginresponse.Email), new DiscordMessageEmbedField("//:", //()),
and the rest as a second webhook

Requiring text along side embed

Would it be possible to use this without having to send text alongside the embed message. As leaving blank throws a error

.

Doesn't work for me. I set up the project and copied the demo code but it doesn't send anything and not throwing any errors.
.NET Framework 4.8, webhook url is valid. I even tried sending a simple message without any embeds or emojis, same result.

Am I missing something?

.NET 2.0 is so old

I think its better to use .NET 7 (If I said the correct version) I got the error that said the code is too old

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.