Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Incorrect HttpService post parameters?

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.

5 comments

0

Why not use a webhook?

0

There's no way to get the messages in a Discord server channel using a webhook.

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.

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.

0

Then why are you sending a request discord and not to the bot itself?

1 answer

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.