bigmoe Whitfield Posted February 26, 2023 Share Posted February 26, 2023 (edited) So I'm setting up a give away with a random number that will be given from this device, but the device must also put this into discord for verification on a private channel that only admins have access too, I know how to get it to give the number to verify, that's not an issue. string WEBHOOK_URL = "https://discord.com/api/webhooks/<removed rest of url"; default { state_entry() { llSetTimerEvent(30); // Change the timer interval as needed } timer() { integer number = llFloor(llFrand(100)) + 1; // Generate a random number between 1 and 100 string message = "Your number is: " + (string)number; // Construct the HTTP request body as a JSON string string json = llDumpList2String([ "content", message ], ","); // Send the HTTP request using llHTTPRequest() return llHTTPRequest(WEBHOOK_URL, [ HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded", HTTP_VERIFY_CERT,TRUE, HTTP_VERBOSE_THROTTLE, TRUE, HTTP_PRAGMA_NO_CACHE, TRUE ], llList2Json(JSON_OBJECT, json)); } } I think I'm missing things, but it's almost 3:30am and I've been at this for 2 hours slamming my head into a wall, I've combined a few working discord scripts and have gotten closer, but dumb me is having issues getting this, any ideas? Edited February 26, 2023 by bigmoe Whitfield I fixed it! 1 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted February 26, 2023 Share Posted February 26, 2023 (edited) llList2Json's second parameter must be a list. You've given it a string. Do this instead: string json = llList2Json(JSON_OBJECT, [ "content", message ]); llHTTPRequest(WEBHOOK_URL, [ // headers ], json); Oh also, don't "return" values from events, they don't have return types. Edited February 26, 2023 by Wulfie Reanimator 2 Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 9 minutes ago, Wulfie Reanimator said: llList2Json's second parameter must be a list. You've given it a string. Do this instead: That works, it's not posting anything to the discord channel and then threw me this error "[00:50] Too many HTTP requests too fast." hmhmh Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 ugh brain fog. but this compiles string WEBHOOK_URL = "you cant haz"; default { state_entry() { llSetTimerEvent(30); // Change the timer interval as needed } timer() { integer number = llFloor(llFrand(100)) + 1; // Generate a random number between 1 and 100 string message = "Your number is: " + (string)number; // Construct the HTTP request body as a JSON string string json = llList2Json ( JSON_OBJECT , [ "content" , message ]); // Send the HTTP request using llHTTPRequest() llHTTPRequest ( WEBHOOK_URL , [ HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded", HTTP_VERIFY_CERT,TRUE, HTTP_VERBOSE_THROTTLE, TRUE, HTTP_PRAGMA_NO_CACHE, TRUE ], json ); } } Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 (edited) nvm, more facepaws, because I thought I fixed it, didnt lol. Edited February 26, 2023 by bigmoe Whitfield 1 Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 @Wulfie Reanimator I got it working, the mime type was wrong! Thank you! 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted February 26, 2023 Share Posted February 26, 2023 FWIW, here's the function I use to push things to discord's webhook: uSendDiscord(string content,string name,string hook) { list lst = ["content",content]; if(name) lst+= ["username",name]; string send = llList2Json(JSON_OBJECT,lst); llHTTPRequest(hook, [ HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/json" ], send); } which usually works well enough for most things (there are more usable json fields in the documentation, but I haven't had much need of them). I know I could "optimize" it, but it's not something that's to be run frequently (by 'things that should be optimized' standards). 1 Link to comment Share on other sites More sharing options...
Xiija Posted February 26, 2023 Share Posted February 26, 2023 (edited) @bigmoe Whitfield here is an example of an embed .... you can do arrays & objects etc.. string slurl(key AvatarID) { string regionname = llGetRegionName(); vector pos = llList2Vector(llGetObjectDetails(AvatarID, [ OBJECT_POS ]), 0); return "http://maps.secondlife.com/secondlife/" + llEscapeURL(regionname) + "/" + (string)llRound(pos.x) + "/" + (string)llRound(pos.y) + "/" + (string)llRound(pos.z) + "/"; } key PostToDiscord(key AvatarID, string Message) { string SLURL = slurl(AvatarID); // call another function to get the slurl string user = llKey2Name( AvatarID ); list json = [ "username", llGetObjectName() + "", "embeds", llList2Json(JSON_ARRAY, [ llList2Json(JSON_OBJECT, [ "color", "100000", "title", "Server Location", "url", SLURL, "description", "\nSender's Profile: http://my.secondlife.com/" + llGetUsername(AvatarID) + "\n \nMsg from " + llGetUsername(AvatarID) + ": \n" + Message + "\n \n.", "author", llList2Json(JSON_OBJECT, [ "name", user, "icon_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/sl_image.png" ]), "footer", llList2Json(JSON_OBJECT, [ "icon_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/sl_image.png", "text", "XMODS Discord Embedder" ]) ]) ]), "avatar_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/thumb_sl_image.png" ]; return llHTTPRequest( WEBHOOK_URL , [ HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/json", HTTP_VERIFY_CERT, TRUE, HTTP_VERBOSE_THROTTLE, TRUE, HTTP_PRAGMA_NO_CACHE, TRUE ], llList2Json(JSON_OBJECT, json) ); } . Edited February 26, 2023 by Xiija Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 I love discord and webhooks and integrating them with lsl, just wish there were more examples and test samples out there. 1 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted February 26, 2023 Share Posted February 26, 2023 How does it work / what does it do? Are you "just" posting the number to a specific Discord channel or..? Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 32 minutes ago, Love Zhaoying said: How does it work / what does it do? Are you "just" posting the number to a specific Discord channel or..? yep, they click a prim, it gives them a number, that number is given to them and to a private discord channel, so if they come to claim a prize they say they won and give us the same number and it matches with the name that clicked it and the number given they get the prize. 1 Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 Slammed into another issue with it, Trying to pass the clickers name with the message to our server... I can get it to throw the key in there but it's zeroed out... which is not helpful. but when attempting to make it place the name with the function it's either not defined in scope or syntax error. I need a break right now though lol, beer time! 1 Link to comment Share on other sites More sharing options...
bigmoe Whitfield Posted February 26, 2023 Author Share Posted February 26, 2023 I have fixed my issue and got a bit of help in world with what I was slamming my head against. it works like a charm now, I thank those of you that came by and helped, this is why I love using the forums. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now