Skip to content

Latest commit

 

History

History
145 lines (117 loc) · 4 KB

README.md

File metadata and controls

145 lines (117 loc) · 4 KB

Build status Documentation Status License: MIT

hook

PowerShell -> Discord Webhook

PSDsHook allows you to easily utilize Discord webhooks via PowerShell.

This module will work with PowerShell version 5.1, with the exception of sending binary files.

If you need to send files to Discord channels, you'll want to use PowerShell Core until support is added for 5.1.

Getting Started

Install module from the PowerShell Gallery

This is the easiest way to use the module! To install it, use:

Install-Module PSDsHook

Then check out the documentation and examples to get started!

Build instructions coming soon if you would like to build it yourself. Simply running build.ps1 should take care of the basic tasks. You can use the module from the /out directory if it compiles.

Quick and Dirty

To create the configuration file, run:

Invoke-PsDsHook -CreateConfig 'https://discordapp.com/api/webhooks/4221456689714954341337/thisisfakeandwillnotwork' -Verbose

To create/send an embed, run:

using module PSDsHook

If the module is not installed into a folder within one of these directories:

($env:PSModulePath -split "$([IO.Path]::PathSeparator)")

You'll need to use the following statement and point it to your local copy of the module's built .psm1 file.

using module 'C:\users\thegn\repos\PsDsHook\out\PSDsHook\0.0.1\PSDsHook.psm1'

(optional) Specify a thumbnail url to use in the hook

$thumbUrl = 'https://static1.squarespace.com/static/5644323de4b07810c0b6db7b/t/5aa44874e4966bde3633b69c/1520715914043/webhook_resized.png'

Create an embed builder object via the [DiscordEmbed] class. You can customize the title and description.

$embedBuilder = [DiscordEmbed]::New(
                    'title',
                    'description'
                )

Add our thumbnail to the embed:

$embedBuilder.AddThumbnail(
    [DiscordThumbnail]::New(
        $thumbUrl
    )
)

Add a couple fields (the $true is for inline and is optional):

$embedBuilder.AddField(
    [DiscordField]::New(
        'field name',
        'field value',
        $true
    )
)

$embedBuilder.AddField(
    [DiscordField]::New(
        'other field name',
        'other field value',
        $true
    )
)

Add a color:

$embedBuilder.WithColor(
    [DiscordColor]::New(
            'purple'
    )
)

Add an author:

$embedBuilder.AddAuthor(
    [DiscordAuthor]::New(
        'Author',
        $thumbUrl
    )
)

Add a footer:

$embedBuilder.AddFooter(
    [DiscordFooter]::New(
        'footer',
        $thumbUrl
    )
)

Add an image:

$embedBuilder.AddImage(
    [DiscordImage]::New(
        $thumbUrl
    )
)

Add a timestamp (no value, defaults to current time you use the command):

$embedBuilder.AddTimeStamp()

Add a custom timestamp (pass in a value of type [DateTime] or one that can be resolved to [DateTime]):

$embedBuilder.AddTimeStamp('5/3/24 05:50:21')

Finally, call the function that will send the embed array to the webhook url:

Invoke-PSDsHook $embedBuilder -Verbose

example