Jump to content

AutoIT including WebHooks for Discord


Recommended Posts

Hello,

Maybe some of you know the program / site "discord.gg", it's a Chat for gamers.

There is a function called "WebHook" which is more or less a little pseudo bot.
You get a link and over this you can let the bot send whatever you want.

For example here is a little bot/webhook that posts the newest NASA articles, including Pictures.
I "created" this with the site "ifttt.com" which manages webhooks for you.

Now my question:
When there is an event detected by my bot,
can i send a message from my Bot directly to my Discord Webhook with the link?
A message like "loot xyz is found"?

If this is not possible, i would try to use a longer way:
When my Bot detects an event,
I would try to trigger "ifttt.com" with something like an email or something else (i still have to figure out what is the best, fastest and securest way) and trigger my Discord Webhook this way, but this would take way longer since it has to go over "ifttt.com"...

 

autoit webhook discord.jpg

autoit webhook discord 2.jpg

Edited by SolemnStrike
Link to comment
Share on other sites

  • 2 weeks later...

Hey it is me again...

I just managed to send a message via a discord webhook in another coding language (screenshot).
As you can see there is not much needed, but still i simply can't make it work in AutoIT. :(
I also tried to use JSON.au3, since this is what Discord wants.
Does someone has time and can write me an example?

webhook example.jpg

Link to comment
Share on other sites

Took me a while but I figured this out for my own use, hope it helps you out as well!

Also remember to switch out the Discord webhook URL for your own.

This requires nothing but an up to date AutoIt, cheers!

Webhook("Awesome")

Func Webhook($Message)
    Local $Url = "https://discordapp.com/api/webhooks/sensitive-data-goes-here"
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    Local $Packet = '{"content": "' & $Message & '"}'
    $oHTTP.open('POST',$Url)
    $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
    $oHTTP.send($Packet)
EndFunc

 

WARNING! This code doesn't work as of January 2nd, 2020!

Read down a bit for an updated function.

Edited by Puls3
Adding a warning

No, I'm not making a bot, keylogger, password stealer, virus, or anything else malicious, there are over a million different reasons someone would ask for whatever I did. Yes, I need to figure out the answer to the exact question I asked because I have valid reasons as to why I'm not using the alternatives. No, I cannot prove I'm not doing anything malicious because this is a forum and that is impossible.

Thank you AutoIt community for always accusing people of doing something evil, good day.

 - The Infamous Impulsive Puls3

Link to comment
Share on other sites

  • 2 weeks later...
On 12.12.2018 at 6:05 AM, Puls3 said:

Took me a while but I figured this out for my own use, hope it helps you out as well!

Also remember to switch out the Discord webhook URL for your own.

This requires nothing but an up to date AutoIt, cheers!

Webhook("Awesome")

Func Webhook($Message)
    Local $Url = "https://discordapp.com/api/webhooks/sensitive-data-goes-here"
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    Local $Packet = '{"content": "' & $Message & '"}'
    $oHTTP.open('POST',$Url)
    $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
    $oHTTP.send($Packet)
EndFunc


It perfectly works!!!!! Big Big Thanks!


#closed

Link to comment
Share on other sites

  • 1 year later...
On 12/23/2018 at 1:50 PM, SolemnStrike said:


It perfectly works!!!!! Big Big Thanks!


#closed

I am attempting to do the exact same thing! I tried the code from above and it doesn't work for me. Am I suppose to include any UDF's or any additional code to make this work, besides what is listed above.

 

Thanks in advance!

Link to comment
Share on other sites

  • Moderators

@Trying2Hard "doesn't work" doesn't help us much. What errors are you getting, or what is happening? Help us help you ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Webhook("Awesome")

Func Webhook($Message)
    Local $Url = "https://discordapp.com/api/webhooks/sensitive-data-goes-here"
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    Local $Packet = '{"content": "' & $Message & '"}'
    $oHTTP.open('POST',$Url)
    $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
    $oHTTP.send($Packet)
EndFunc

 

Using the latest version of auto it, I replaced "https://discordapp.com/api/webhooks/sensitive-data-goes-here" with the webhook provided to me by Discord. Ran the script and nothing happens. I wasn't sure if I needed to INCLUDE a UDF or any of the files, because if you look at the code above - none of that is referenced. The script runs and does nothing. 

 

Scite provides this at the end of the script:
>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Ronnie\Desktop\Last Test.au3"    
>Exit code: 0    Time: 0.06764

Link to comment
Share on other sites

Wow, it has been a long time since I've written in AutoIt, and a long time since I commented here.

Don't worry @Trying2Hard it wasn't working when I tried it either, the issue was that Discord modified their Webhook requirements and were sending an Error 404; Bad Request. I've now modified the code to work after Discord's changes by setting the header to json seeing as we're sending a json object. Took me hours to figure that out. Also side note, as I said in the last comment it's pure AutoIt, no UDFs.

 

As I said before, remember to switch out the Discord webhook URL for your own.

This requires nothing but an up to date AutoIt, cheers! 

Webhook("Awesome")

Func Webhook($Message)
    Local $Url = "https://discordapp.com/api/webhooks/sensitive-data-goes-here"
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    Local $Packet = '{"content": "' & $Message & '"}'
    $oHTTP.open('POST',$Url)
    $oHTTP.setRequestHeader("Content-Type","application/json")
    $oHTTP.send($Packet)
EndFunc

 

Edited by Puls3
clarification

No, I'm not making a bot, keylogger, password stealer, virus, or anything else malicious, there are over a million different reasons someone would ask for whatever I did. Yes, I need to figure out the answer to the exact question I asked because I have valid reasons as to why I'm not using the alternatives. No, I cannot prove I'm not doing anything malicious because this is a forum and that is impossible.

Thank you AutoIt community for always accusing people of doing something evil, good day.

 - The Infamous Impulsive Puls3

Link to comment
Share on other sites

  • 1 year later...
On 1/2/2020 at 3:47 PM, Puls3 said:

Wow, it has been a long time since I've written in AutoIt, and a long time since I commented here.

Don't worry @Trying2Hard it wasn't working when I tried it either, the issue was that Discord modified their Webhook requirements and were sending an Error 404; Bad Request. I've now modified the code to work after Discord's changes by setting the header to json seeing as we're sending a json object. Took me hours to figure that out. Also side note, as I said in the last comment it's pure AutoIt, no UDFs.

 

As I said before, remember to switch out the Discord webhook URL for your own.

This requires nothing but an up to date AutoIt, cheers! 

Webhook("Awesome")

Func Webhook($Message)
    Local $Url = "https://discordapp.com/api/webhooks/sensitive-data-goes-here"
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    Local $Packet = '{"content": "' & $Message & '"}'
    $oHTTP.open('POST',$Url)
    $oHTTP.setRequestHeader("Content-Type","application/json")
    $oHTTP.send($Packet)
EndFunc

 

Hello Sir i copied your Webhook function for my personal script, it works most of the time but sometimes i am getting an error, i thought about it but did not really found a solution, so if you read this i would be gald if you could help me out.

https://gyazo.com/5b0c7b7c1cf115146bf887458c6f1592

Thank you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...