2

So I am trying to send a message to a discord webhook in Lua.
Currently I have this code:

local http = require("socket.http")
ltn12 = require("ltn12")

local payload = [[ {"username":"NAME","avatar_url":"","content":"MESSAGE"} ]]

http.request
{
    url = "https://discordapp.com/api/webhooks/<redacted>",
    method = "POST",
    headers =
    {
        ["Content-Type"] = "application/json",
        ["Content-Length"] = payload:len()
    },
    source = ltn12.source.string(payload),
}

That I found here: http://forum.micasaverde.com/index.php?topic=32035.0
But the message never arrives. What am I doing wrong?

Edit: I tested a bit and it seems like I get a 301 error code when I send this to the discord webhook.

OldLazarus
  • 71
  • 1
  • 6
  • https://stackoverflow.com/a/37555539/1190388 – hjpotter92 Jun 26 '20 at 20:24
  • are you literally sending it to "URL", or did you just remove the actual webhook URL? If so, maybe change it to something like `https://discordapp.com/api/webhooks/` so it's more clear that you're using a proper URL. – DarkWiiPlayer Jun 26 '20 at 20:34
  • Thanks @hjpotter92 your comment helped me solve this problem – OldLazarus Jun 27 '20 at 09:07
  • Does this answer your question? [luaSocket HTTP requests always respond with a redirect (301 or 302)](https://stackoverflow.com/questions/37555226/luasocket-http-requests-always-respond-with-a-redirect-301-or-302) – hjpotter92 Jun 27 '20 at 09:15
  • I already installed luasocket und solved it with ssl.https like stated in the first post you commented – OldLazarus Jun 27 '20 at 09:33

0 Answers0