Page 1 of 1

Send Message to Discord Using API

Posted: 08 Sep 2017, 11:02
by Delta Pythagorean
Probably been asked, and I don't want to fish out the commands and functions from Geek's Discord.ahk.
What is the "mini-script" that sends a message to a specified channel of Discord?

Re: Send Message to Discord Using API  Topic is solved

Posted: 08 Sep 2017, 11:04
by Delta Pythagorean
Nevermind I had the code in a file.
I'm stupid.

Code: Select all

Text := StrReplace(StrReplace(Text, "\", "\\"), """", "\""")
Http := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
Http.Open("POST", "https://discordapp.com/api/channels/" ChanID "/messages")
Out := Http.Open("GET", "https://discordapp.com/api/channels/" ChanID)
Http.SetRequestHeader("Authorization", Token)
Http.SetRequestHeader("Content-Type", "application/json")
Http.Send("{""content"": """ Text """}")

Re: Send Message to Discord Using API

Posted: 21 Jun 2018, 18:37
by dragonre
I've set up a discord bot, joined it to my server. In your code I replaced ChanID with my channel ID, the Token with my bot's token, and put in my own text. When I try to send a test message I don't get an error, but no message is sent. Is there something else I'm missing?

Re: Send Message to Discord Using API

Posted: 02 Dec 2019, 20:34
by dzint
Ive been trying to figure this out but I cant get it to work, can you send some example code that works to send a message to discord webhook?

Re: Send Message to Discord Using API

Posted: 21 Mar 2022, 18:59
by EntropicBlackhole
Delta, I've tried setting it up too but it won't send really, and g33kdude says that Discord.ahk is probably outdated since the api has changed, so it might be that, do you have perhaps an updated version? or an updated version of discord.ahk?