Hello wonderful persons of ahk community
I'm using a script I found, to send messages to my discord server (without opening browser or app) just an inputbox to type a msg and bye
It send it as a bot , and does the job quite good
but when it comes to some messages with special character, it fails
i'm not a pro of http requests and don't know the real problem.
I figured that the message in the content part is not encoded properly
I tried URLencode function on it. it works, but in Discord you see the message encoded too
It is unredable of course (a block of text with a lot of %20)
i don't how the text should be encoded
any help ?
Code: Select all
Send_Msg_to_Discord(msg,Url="MyWebhookURL"){
;Default parmaeter is url of general Of my server
EncodedMsg := UrlEncode(msg)
postdata=
(
{
"content": "%EncodedMsg%"
}
) ;Use https://leovoel.github.io/embed-visualizer/ to generate above webhook code
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", url, false)
WebRequest.SetRequestHeader("Content-Type", "application/json")
WebRequest.Send(postdata)
}
; urlEncode [by RaptorX]
urlEncode(url){
f = %A_FormatInteger%
SetFormat, Integer, Hex
While (RegexMatch(url,"\W", var))
StringReplace, url, url, %var%, % asc(var), All
StringReplace, url, url, 0x, `%, All
SetFormat, Integer, %f%
return url
}