Hi there. I was wondering why this code below isn’t working:
It says can not cast std::string on the line just before the end. Why is this?
If someone could help that would be great and much appreciated! Thanks!
Hi there. I was wondering why this code below isn’t working:
It says can not cast std::string on the line just before the end. Why is this?
If someone could help that would be great and much appreciated! Thanks!
You probably need a web-hook link or channel link?
No. You can clearly see they are using a variable for that. They shouldn’t be revealing the actual URL either.
The error the author is encountering basically means malformed data, so most likely one of the variables are not JSON-serialisable OR they’re not what the server expected to get.
so basically, if the outcome is ban, the script adds the player to the ban table. now, if this was successfully done, the script sends an embed to the discord channel. unbantime is how long the player is banned for, and reason is the reason they are banned for
Yes, but what are their types? What are their values? Integers, strings, tables…?
Their just numbers really. I’m not too much of a scripter myself. Ik a few things.
You forgot to JSONEncode the data. Do this:
data = HttpServ:JSONEncode(data)
HttpServ:PostAsync() -- code
If they’re numbers, then you’ve got to convert them to a string using tostring(variable)
(however I doubt you save the reason as a number, however I’m suspecting you may be passing the unban date as os.date()
or os.time()
- in that case you should convert it to a string, or use os.date()
's format string, which probably is what you want to do).
I’ve also noticed you’re decoding the output rather than encoding the input. You’d want to change HttpService:PostAsync(url,data):JSONDecode(data)
to HttpService:PostAsync(url,HttpService:JSONEncode(data))
.
Thanks a lot. I’ll see if it works!
ok so it says: HTTP 400 (bad request)
new code:
Im pretty sure roblox/discord blocked web hooks because all of my web hooks randomly stopped working one day, probably going to need a proxy
no they still work fine for me
This usually happens when the URL is incorrect or there is some error in the table. Is the URL correct?
I’ll check. Thanks for the help!
Just a few points here:
Do not post pictures of the code: Instead, use codeblocks. They allow us to copy and easily edit your code. Sometimes, pictures may be unclear and for future reference, if you have an issue, we can easily alter your code if you paste in a codeblock.
Format for codeblocks:
```lua
code here
```
Regarding your issue, embeds do not have a content
field. You probably meant title
instead of content
. Also, 0xFFFFFF
is already a number (it is a hexadecimal number). Although it works if you convert it to a base 10 number via tonumber
, it works even without the tonumber
function
Since discord doesn’t inform you of what’s malformed in the request body you sent, you should always refer to Discord’s Documentation. If you still can’t figure out what’s wrong, it usually helps to remove a field from the request and them send the request one-by-one. That way, you can find what is specifically wrong with the request
Hmm, there’s one thing you can do about this, fix the link
Thanks for the advice and help!
Thank you so much! It all works now! Thanks for the help!