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