{"id":1286,"date":"2021-01-22T09:44:39","date_gmt":"2021-01-22T15:44:39","guid":{"rendered":"http:\/\/ninmonkeys.com\/blog\/?p=1286"},"modified":"2021-01-22T10:21:50","modified_gmt":"2021-01-22T16:21:50","slug":"creating-a-discord-webhook-in-a-few-lines-of-powershell","status":"publish","type":"post","link":"https:\/\/www.ninmonkeys.com\/blog\/2021\/01\/22\/creating-a-discord-webhook-in-a-few-lines-of-powershell\/","title":{"rendered":"Creating a Discord Webhook in a few lines of PowerShell"},"content":{"rendered":"\n\n\n<p class=\"wp-block-paragraph\">Discord Web Hooks are easier than you&#8217;d think. <a href=\"https:\/\/discord.com\/developers\/docs\/resources\/webhook#execute-webhook\">It uses a regular `HTTP` web request<\/a> . <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step1: Creating your webhook url<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go to: Server Settings -&gt; Integrations -&gt; View Webhooks<br>Then click create webhook.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-25.png\" alt=\"\" class=\"wp-image-1290\" width=\"610\" height=\"261\" srcset=\"https:\/\/www.ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-25.png 738w, https:\/\/www.ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-25-300x128.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><figcaption>Choose a name, the channel, then <code class=\"\" data-line=\"\">copy webhook url<\/code><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step2: Invoke-RestMethod<\/h2>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">$webhookUri = &#039;https:\/\/discord.com\/api\/YourWebhookUrlHere&#039;\n\n$Body = @{\n  &#039;username&#039; = &#039;Nomad&#039;\n  &#039;content&#039; = &#039;https:\/\/memory-alpha.fandom.com\/wiki\/Nomad&#039;\n}\nInvoke-RestMethod -Uri $webhookUri -Method &#039;post&#039; -Body $Body<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Success!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-26.png\" alt=\"\" class=\"wp-image-1299\" width=\"542\" height=\"470\" srcset=\"https:\/\/www.ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-26.png 542w, https:\/\/www.ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-26-300x260.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Docs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are optional webhook arguments to customize the output: <a href=\"https:\/\/discord.com\/developers\/docs\/resources\/webhook#execute-webhook\">https:\/\/discord.com\/developers\/docs\/resources\/webhook#execute-webhook<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comparison with <code class=\"\" data-line=\"\">curl<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I tried making <code class=\"\" data-line=\"\">curl<\/code> easier to read by splitting content, and pipe so that you don&#8217;t have to manually escape <code class=\"\" data-line=\"\">Json<\/code><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\" data-line=\"\">$Json = @{ &#039;username&#039; = &#039;Nomad&#039;; &#039;content&#039; = &#039;https:\/\/memory-alpha.fandom.com\/wiki\/Nomad&#039; } | ConvertTo-Json -Compress\n\n$Json | curl -X POST -H &#039;Content-Type: application\/json&#039; -d &#039;@-&#039; $webhookUri<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discord Web Hooks are easier than you&#8217;d think. It uses a regular `HTTP` web request . Step1: Creating your webhook url Go to: Server Settings -&gt; Integrations -&gt; View WebhooksThen click create webhook. Step2: Invoke-RestMethod Success! Docs There are optional webhook arguments to customize the output: https:\/\/discord.com\/developers\/docs\/resources\/webhook#execute-webhook Comparison with curl I tried making curl easier [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,40],"tags":[68,4,64,69],"class_list":["post-1286","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-tip","tag-discord","tag-powershell","tag-web-api","tag-webhook"],"_links":{"self":[{"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts\/1286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/comments?post=1286"}],"version-history":[{"count":21,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1311,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts\/1286\/revisions\/1311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/media\/1289"}],"wp:attachment":[{"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/media?parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/categories?post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ninmonkeys.com\/blog\/wp-json\/wp\/v2\/tags?post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}