Skip to content

Instantly share code, notes, and snippets.

@Neodevils
Created March 15, 2024 01:11
Show Gist options
  • Save Neodevils/eda4d97a395773e176142fbb4975f759 to your computer and use it in GitHub Desktop.
Save Neodevils/eda4d97a395773e176142fbb4975f759 to your computer and use it in GitHub Desktop.
Code Snippet for Adding Banner to Discord App

App Banner Code

import fetch from "node-fetch";

async function updateBanner() {
    const BOT_TOKEN = "";
    try {
        const response = await fetch("https://discord.com/api/v10/users/@me", {
            method: "PATCH",
            headers: {
                Authorization:
                    `Bot ${BOT_TOKEN}`,
                "Content-Type": "application/json",
            },
            body: JSON.stringify({ banner: "data:image/png;base64..." }), 
        });

        const data = await response.json();
        console.log(data);
    } catch (error) {
        console.error("Error:", error);
    }
}

updateBanner();

IMPORTANT!

Thanks to @fox3000foxy for sharing snippet.

  1. Put your app's token on "BOT_TOKEN" variable.
  2. Use a converter, such as: https://ezgif.com/image-to-datauri/
  3. Replace the banner field by the data url of your banner.
  4. node file.js

App Banner Image

image

@EZ200
Copy link

EZ200 commented Mar 15, 2024

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\a1989\Desktop\Banner Discord\node_modules\node-fetch\src\index.js from C:\Users\a1989\Desktop\Banner Discord\file.js not supported.
Instead change the require of index.js in C:\Users\a1989\Desktop\Banner Discord\file.js to a dynamic import() which is available in all CommonJS modules.
at Object. (C:\Users\a1989\Desktop\Banner Discord\file.js:1:15) {
code: 'ERR_REQUIRE_ESM'
}

@Neodevils
Copy link
Author

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\a1989\Desktop\Banner Discord\node_modules\node-fetch\src\index.js from C:\Users\a1989\Desktop\Banner Discord\file.js not supported. Instead change the require of index.js in C:\Users\a1989\Desktop\Banner Discord\file.js to a dynamic import() which is available in all CommonJS modules. at Object. (C:\Users\a1989\Desktop\Banner Discord\file.js:1:15) { code: 'ERR_REQUIRE_ESM' }

The code I used is for "module" type projects. Go to your package.json file and add:

"type": "module"

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