{"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:\/\/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>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>Step1: Creating your webhook url<\/h2>\n\n\n\n<p>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\" src=\"https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-25.png\" alt=\"\" class=\"wp-image-1290\" width=\"610\" height=\"261\" srcset=\"https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-25.png 738w, https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-25-300x128.png 300w\" sizes=\"(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>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>Success!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-26.png\" alt=\"\" class=\"wp-image-1299\" width=\"542\" height=\"470\" srcset=\"https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-26.png 542w, https:\/\/ninmonkeys.com\/blog\/wp-content\/uploads\/2021\/01\/image-26-300x260.png 300w\" sizes=\"(max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<h2>Docs<\/h2>\n\n\n\n<p>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>Comparison with <code class=\"\" data-line=\"\">curl<\/code><\/h2>\n\n\n\n<p>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><\/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":[],"categories":[18,40],"tags":[68,4,64,69],"_links":{"self":[{"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts\/1286"}],"collection":[{"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/comments?post=1286"}],"version-history":[{"count":21,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1311,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/posts\/1286\/revisions\/1311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/media\/1289"}],"wp:attachment":[{"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/media?parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/categories?post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ninmonkeys.com\/blog\/wp-json\/wp\/v2\/tags?post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}