From b7bae5dd4b5edbc0d703250b981f6ede81550653 Mon Sep 17 00:00:00 2001 From: Alex Gravely Date: Fri, 18 Jan 2019 12:12:06 -0500 Subject: [PATCH] Add Webhook example. --- Discord.Net.sln | 21 ++++++++++-- .../04_webhook_client.csproj | 13 +++++++ samples/04_webhook_client/Program.cs | 34 +++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 samples/04_webhook_client/04_webhook_client.csproj create mode 100644 samples/04_webhook_client/Program.cs diff --git a/Discord.Net.sln b/Discord.Net.sln index 245515c7c..c776506d5 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2009 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28407.52 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" EndProject @@ -30,7 +30,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01_basic_ping_bot", "sample EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02_commands_framework", "samples\02_commands_framework\02_commands_framework.csproj", "{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03_sharded_client", "samples\03_sharded_client\03_sharded_client.csproj", "{9B4C4AFB-3D15-44C6-9E36-12ED625AAA26}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03_sharded_client", "samples\03_sharded_client\03_sharded_client.csproj", "{9B4C4AFB-3D15-44C6-9E36-12ED625AAA26}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "04_webhook_client", "samples\04_webhook_client\04_webhook_client.csproj", "{88B77A5B-0BC0-4E99-8FD9-D83F6999F562}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -174,6 +176,18 @@ Global {9B4C4AFB-3D15-44C6-9E36-12ED625AAA26}.Release|x64.Build.0 = Release|Any CPU {9B4C4AFB-3D15-44C6-9E36-12ED625AAA26}.Release|x86.ActiveCfg = Release|Any CPU {9B4C4AFB-3D15-44C6-9E36-12ED625AAA26}.Release|x86.Build.0 = Release|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Debug|x64.ActiveCfg = Debug|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Debug|x64.Build.0 = Debug|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Debug|x86.ActiveCfg = Debug|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Debug|x86.Build.0 = Debug|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Release|Any CPU.Build.0 = Release|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Release|x64.ActiveCfg = Release|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Release|x64.Build.0 = Release|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Release|x86.ActiveCfg = Release|Any CPU + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -188,6 +202,7 @@ Global {F2FF84FB-F6AD-47E5-9EE5-18206CAE136E} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} {4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} {9B4C4AFB-3D15-44C6-9E36-12ED625AAA26} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} + {88B77A5B-0BC0-4E99-8FD9-D83F6999F562} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D2404771-EEC8-45F2-9D71-F3373F6C1495} diff --git a/samples/04_webhook_client/04_webhook_client.csproj b/samples/04_webhook_client/04_webhook_client.csproj new file mode 100644 index 000000000..c8d0c9ad3 --- /dev/null +++ b/samples/04_webhook_client/04_webhook_client.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp2.2 + _04_webhook_client + + + + + + + diff --git a/samples/04_webhook_client/Program.cs b/samples/04_webhook_client/Program.cs new file mode 100644 index 000000000..986ea32b4 --- /dev/null +++ b/samples/04_webhook_client/Program.cs @@ -0,0 +1,34 @@ +using Discord; +using Discord.Webhook; +using System.Threading.Tasks; + +namespace _04_webhook_client +{ + // This is a minimal example of using Discord.Net's Webhook Client + // Webhooks are send-only components of Discord that allow you to make a POST request + // To a channel specific URL to send a message to that channel. + class Program + { + static void Main(string[] args) + => new Program().MainAsync().GetAwaiter().GetResult(); + + public async Task MainAsync() + { + // The webhook url follows the format https://discordapp.com/api/webhooks/{id}/{token} + // Because anyone with the webhook URL can use your webhook + // you should NOT hard code the URL or ID + token into your application. + using (var client = new DiscordWebhookClient(webhookId: 0, webhookToken:"")) + { + var embed = new EmbedBuilder + { + Title = "Test Embed", + Description = "Test Description" + }; + + // Webhooks are able to send multiple embeds per message + // As such, your embeds must be passed as a collection. + await client.SendMessageAsync(text: "Send a message to this webhook!", embeds: new[] { embed.Build() }); + } + } + } +}