Skip to content

Instantly share code, notes, and snippets.

@BachLe2000
Last active October 28, 2025 16:04
Show Gist options
  • Select an option

  • Save BachLe2000/2487b1df2ac45ae94ad3e06191188655 to your computer and use it in GitHub Desktop.

Select an option

Save BachLe2000/2487b1df2ac45ae94ad3e06191188655 to your computer and use it in GitHub Desktop.
Send Video File As Clip

Send video file as clip

How to use this:

  1. Prepare your video file by using the clip metadata snippet in the Requirement section below.
  2. Press Ctrl+Shift+I to open DevTools and copy everything in Main Function section.

Note

If there is nothing poping up, you can:

  • Download the ptb client, or
  • Use this to enable DevTools on stable client.

If you're unable to paste the snippet into the console, you might have to type allow pasting and hit enter

  1. Select the file with metadata you modified in the file upload window.
  2. Copy the snippet in Usage section, modify it to your preferrence and press enter.
  3. Wait until everything is done.

Tip

If you got {"message": "Not a valid clip", "code": 50174} error after upload AND even your video file has proper metadata then follow these steps:

Thanks eaglePB2 for the invalid clip fix!

  1. Install FFmpeg
  • On Windows: check WikiHow for step-by-step for how to install it and add to PATH.
  • On Mac: use Homebrew brew install ffmpeg.
  • On Linux: use your package manager, e.g., sudo apt install ffmpeg.
  1. Re-encode the clip by opening your terminal and paste:

ffmpeg -i "PATH_TO\invalid_clip.mp4" -movflags +faststart -pix_fmt yuv420p -c:v libx264 -profile:v high -level 4.0 -c:a aac -b:a 128k > "PATH_TO\fixed_clip.mp4"

  1. Update the clip metadata:
delete window.$;
let wpRequire = webpackChunkdiscord_app.push([[Symbol()], {}, r => r]);
webpackChunkdiscord_app.pop();
Object.values(wpRequire.c).find(x => x?.exports?.Z?.__proto__?.getMediaEngine).exports.Z.getMediaEngine().updateClipMetadata("PATH_TO\\fixed_file.mp4", "{}")

Requirement

  • Has clip metadata in that file

You can add metadata by using this snippet, NOT work in the browser, use Discord app client instead:

delete window.$;
let wpRequire = webpackChunkdiscord_app.push([[Symbol()], {}, r => r]);
webpackChunkdiscord_app.pop();
Object.values(wpRequire.c).find(x => x?.exports?.Z?.__proto__?.getMediaEngine).exports.Z.getMediaEngine().updateClipMetadata("<LOCAL_FILE_PATH>","{}")

<LOCAL_FILE_PATH>: Your local path to your file. (Eg: C:\\Users\\bachhummus\\Downloads\\Video\\promo.mp4)

Snippet

  • Main Function:
delete window.$;
let wpRequire = webpackChunkdiscord_app.push([[Symbol()], {}, r => r]);
webpackChunkdiscord_app.pop();
let RestAPI = Object.values(wpRequire.c).find(x => x?.exports?.tn?.get).exports.tn;

function chooseFile() {
    return new Promise((r) => {
        let t = document.createElement('input');
        (t.type = 'file'),
            (t.accept = '*'),
            (t.style.display = 'none'),
            document.body.appendChild(t),
            t.click(),
            t.addEventListener('change', () => {
                r(t.files[0]), t.remove();
            });
    });
}

function uploadFile(url, file) {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.onload = function(event) {
            fetch(url, {
                method: "PUT",
                body: event.target.result,
                referrer: "https://discord.com/",
                referrerPolicy: "strict-origin-when-cross-origin",
                mode: "cors",
                credentials: "omit"
            })
            .then(res => resolve(res.ok))
            .catch(err => reject(err));
        };
        reader.readAsArrayBuffer(file);
    });
}
async function startClipUpload({
    fileName = "clip.mp4",
    participants = [],
    title = "Untitled Clip",
    spoiler = false,
    remix = false,
    thumbnail = false,
    createdAt = new Date().toISOString(),
    message = "",
    mimeTypes = "*/*",
    channelId = null,
    applicationId = null
} = {}) {
    const targetChannelId = channelId || Object.values(wpRequire.c).find(x => x?.exports?.Z?.__proto__?.getCurrentlySelectedChannelId).exports.Z.getCurrentlySelectedChannelId();

    const file = await chooseFile(mimeTypes);
    if (!file) {
        console.error('%c[Error] %cNo file selected', 'color: red', '');
        return;
    }

    let attachmentResponse;
    try {
        attachmentResponse = await RestAPI.post({
            url: `/channels/${targetChannelId}/attachments`,
            body: {
                content: message,
                files: [{
                    filename: fileName,
                    file_size: file.size,
                    id: `${Math.floor(1e3 * Math.random())}`,
                    is_clip: true,
                    is_spoiler: spoiler,
                    is_remix: remix,
                    is_thumbnail: thumbnail,
                    clip_created_at: createdAt,
                    clip_participant_ids: participants,
                    title: title,
                    application_id: applicationId
                }]
            }
        });
    } catch (err) {
        console.error('%c[Error] %cFailed to upload file.', 'color: red', '');
        return;
    }

    const parsed = JSON.parse(attachmentResponse.text);
    const attachment = parsed.attachments[0];

    const uploadResult = await uploadFile(attachment.upload_url, file);
    if (!uploadResult) {
        console.error('%c[Error] %cUpload failed', 'color: red', '');
        return;
    }

    const sendMessageResult = await RestAPI.post({
        url: `/channels/${targetChannelId}/messages`,
        body: {
            content: message,
            attachments: [{
                id: '0',
                filesize: file.size,
                filename: fileName,
                uploaded_filename: attachment.upload_filename,
                is_clip: true,
                is_spoiler: spoiler,
                is_remix: remix,
                is_thumbnail: thumbnail,
                clip_created_at: createdAt,
                clip_participant_ids: participants,
                title: title,
                application_id: applicationId
            }]
        }
    }).catch(err => err);

    if (!sendMessageResult.ok) {
        console.error(`%c[Error] %c${sendMessageResult.text}`, 'color: red', '');
        return;
    }

    console.log('%c[Success] %cClip uploaded and message sent', 'color: green', '');
}
  • Usage:
startClipUpload({
    fileName: "my_clip.mp4",
    participants: ["624091967625625610", "669627189624307712"],
    title: "Epic Moment",
    spoiler: false,
    remix: false,
    thumbnail: false,
    createdAt: "2025-10-23T15:30:00.000Z",
    message: "Check out this clip!\nAmazing moment!",
	channelId: null, // or "<CHANNEL ID>"
	applicationId: null // or "<APPLICATION ID>"
});

Option

  • fileName: string - desired file name for the clip (e.g., "my_clip.mp4")
  • participants: string[] - list of user IDs to add as clip participants (e.g, ["624091967625625610", "669627189624307712", "1008776202191634432", "643945264868098049", "1081004946872352958"])
  • title: string - title of the clip (e.g., "Epic Moment")
  • spoiler: boolean - mark the clip as a spoiler (true or false)
  • remix: boolean - mark the clip as a remix (true or false)
  • thumbnail: boolean - mark the clip as a thumbnail (true or false)

⚠️ Setting true will make the clip invisible

  • createdAt: string - ISO 8601 timestamp of clip creation (e.g., "2025-10-23T15:30:00.000Z")
  • message: string - message content to send with the clip

Use \n for line breaks, e.g., "Hi everyone\nBye chat"

  • channelId: string - channel ID to send the clip, if null then default to current channel you are viewing (e.g., "1405752033784496199")
  • applicationId: string - the ID of the application the clip was taken in, can be null (e.g., "1402418491272986635")

You can obtain application ID from https://disgamebrowser.openasar.dev/ and click on the ID icon, or use any of your created application in your Discord Developer Portal.

Credit

@BachLe2000
Copy link
Author

BachLe2000 commented Jan 30, 2024

pls leave ur feedback, error in da comment or in my forum post in discord previews, wc, deh,...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment