Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Incorrect HttpService post parameters?

Asked by 6 years ago

I'm working on a system that allows communication from ROBLOX to Discord via a bot.

When using PostAsync, these are my parameters:

local Data = {
    ["Authorization"] = "auth_code" -- this is normally a string with an auth code, however for security reasons I can't include it
}

game:GetService("HttpService"):PostAsync("https://discordapp.com/api/guilds/1337/members",false,Data) -- 1337 was also a guild code. However, I can't include it for privacy

When running this, I get the error 'Unable to cast Dictionary to token'

Any help is appreciated. Cheers.

0
Why not use a webhook? User#5423 17 — 6y
0
There's no way to get the messages in a Discord server channel using a webhook. bombsaway8 0 — 6y
0
You need to cast it to JSON. No web developer will build an API that will understand all these table formats in all these languages. hiimgoodpack 2009 — 6y
0
That's not the case. I actually made a mistake, which was using 'PostAsync' instead of 'GetAsync'. If you cast it to JSON then it'll throw an error. bombsaway8 0 — 6y
0
Then why are you sending a request discord and not to the bot itself? User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

The reason this is not working is because for the function :PostAsync() the first three parameter datatypes are String, String, HttpContenType. You have String, bool, table. What you should do is this

local Data = {
    ["Authorization"] = "auth_code" -- this is normally a string with an auth code, however for security reasons I can't include it
}

game:GetService("HttpService"):PostAsync("https://discordapp.com/api/guilds/1337/members",Data) -- 1337 was also a guild code. However, I can't include it for privacy

Now you are satisfying the first two parameters of the function

But this still wouldnt work, why? because you cant send a table over as data, you have to turn it into JSON so it can be passed by using :JSONEncode()

local Data = {
    ["Authorization"] = "auth_code" -- this is normally a string with an auth code, however for security reasons I can't include it
}

game:GetService("HttpService"):PostAsync("https://discordapp.com/api/guilds/1337/members",game:GetService("HttpService"):JSONEncode(Data)) -- 1337 was also a guild code. However, I can't include it for privacy

You can later Decode a receiving JSON with :JSONDecode()

Ad

Answer this question