Jump to content

LSL discord issue - Resolved!


bigmoe Whitfield
 Share

You are about to reply to a thread that has been inactive for 426 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

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 by bigmoe Whitfield
I fixed it!
  • Thanks 1
Link to comment
Share on other sites

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 by Wulfie Reanimator
  • Like 2
Link to comment
Share on other sites

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

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

  • Thanks 1
Link to comment
Share on other sites

@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 by Xiija
Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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!

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 426 days.

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
 Share

×
×
  • Create New...