EvotecIT / PSDiscord

Simple PowerShell module allowing to send messages to Discord Channel over webhooks
47 stars 7 forks source link

Invoke-RestMethod : {"embeds": ["0"]} #2

Closed JGit85 closed 5 years ago

JGit85 commented 5 years ago

I had tested this a few times and had it working, but now without any code changes I am receiving the following:

Invoke-RestMethod : {"embeds": ["0"]}
At C:\Program Files\WindowsPowerShell\Modules\PSDiscord\0.2.2\PSDiscord.psm1:169 char:9
+         Invoke-RestMethod -Uri $WebHookUrl -Body $Body -Method Post - ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Any ideas? Here is the snippet of code relating to the discord message:

# Discord message/notification configuration
$Uri = 'webook url here'
$Author = New-DiscordAuthor -Name 'Name' -IconUrl "image url here"
$Fact = New-DiscordFact -Name ' ' -Value 'message' -Inline $false
$Thumbnail = New-DiscordThumbnail -Url "image url here"
$Section = New-DiscordSection -Title 'message' -Description '' -Facts $Fact -Color Red -Author $Author -Thumbnail $Thumbnail -Image $Thumbnail
Send-DiscordMessage -WebHookUrl $Uri -Sections $Section -AvatarName 'NoPixelChecker' -AvatarUrl "image url here"
PrzemyslawKlys commented 5 years ago

From testing your code it seems problem is within $Fact. You can't have an empty name. If you give a name it will work.

Describe 'Send-DiscordMessage - Invoke-RestMethod Test' {
    It 'Given - Few settings' {
        # Discord message/notification configuration
        $Uri = $Env:DiscordUrl
        $Author = New-DiscordAuthor -Name 'Name' -IconUrl "https://raw.githubusercontent.com/EvotecIT/PSTeams/master/Links/Asset%20130.png"
        $Fact = New-DiscordFact -Name 'Test' -Value 'message' -Inline $false
        $Thumbnail = New-DiscordThumbnail -Url "https://raw.githubusercontent.com/EvotecIT/PSTeams/master/Links/Asset%20130.png"
        $Section = New-DiscordSection -Title 'message' -Description '' -Facts $Fact -Color Red -Author $Author -Thumbnail $Thumbnail -Image $Thumbnail
        Send-DiscordMessage -WebHookUrl $Uri -Sections $Section -AvatarName 'NoPixelChecker' -AvatarUrl "https://raw.githubusercontent.com/EvotecIT/PSTeams/master/Links/Asset%20130.png"
    }
}