Jump to content

Discord Webhook upload image


Recommended Posts

Hi, I need help to code that sends a photo to a Discord using his webhook, but I can't get it to work.
I'm using the 'takePlayerScreenShot' and 'onPlayerScreenShot'
I've made several attempts with the code, but none of them have work...

I can't really find any useful information that works.

Link to comment
  • Moderators
21 hours ago, RekZ said:

I can't really find any useful information that works.

How about screenSource?

Here a few lines of code I copied out of my smartphone remote control app. I can vaguely remember that there were some limits I ran in to, which is why the resolution is so low. But not sure which component was affected by it -> probably the JSON format by callRemote. I probably should have used fetchRemote instead, but didn't know better at that time.

 

Client

myScreenSource = dxCreateScreenSource( 640 / 2, 480 / 2 )

--- ...

dxUpdateScreenSource( myScreenSource )
local pixels = dxGetTexturePixels( myScreenSource )
local jpegPixels = dxConvertPixels( pixels, 'jpeg', 20 )
triggerServerEvent( "screen-stream", localPlayer, jpegPixels )

--- ...

 

Server

addEvent( "screen-stream", true )
addEventHandler( "screen-stream", root, function( jpegPixels )

	callRemote( "http://127.0.0.1:3134/stream", result, base64Encode( jpegPixels ) ) -- 

end )

 

App

http.createServer(function (req, res) {
    if (req.url == "/stream") {
        const chunks = [];
        req.on('data', chunk => chunks.push(chunk));
        req.on('end', () => {
            const data = JSON.parse(Buffer.concat(chunks).toString('utf8'));

            if (data != undefined && data[0] != undefined) {
               // I used socket IO to send the screenshots to my Phone
               // io.emit('broadcast', data[0].toString('base64'));
               // base64 image: "data:image/jpeg;base64," + data[0].toString('base64')
            }
        })
    }
    res.end();
}).listen(3134, "127.0.0.1");

 

Web browser:

const image = new Image(2560, 1440);
// Socket IO
socket.on("broadcast", data => {
	image.src = "data:image/jpeg;base64," + data // Replace an image with my screen
});

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...