Skip to content

Instantly share code, notes, and snippets.

@535i
Created March 15, 2024 17:04
Show Gist options
  • Save 535i/408de1e7744bab4218ceb2510b821655 to your computer and use it in GitHub Desktop.
Save 535i/408de1e7744bab4218ceb2510b821655 to your computer and use it in GitHub Desktop.
Change the banner of your discord bot

Discord Bot Banner with Python

import requests
import base64
import os

token = "bot_token" #Your Bot token
path = "file.png" #The path to your image file

def file_type(image_path):
    name, extension = os.path.splitext(image_path)
    return extension[1:]

with open(path, 'rb') as f:
    image = f.read()
    encoded_img = base64.b64encode(image).decode('utf-8')

file_extension = file_type(path)
data = f'data:image/{file_extension};base64,{encoded_img}'

headers = {
    "Authorization": f"Bot {token}",
    "Content-Type": "application/json",
}
payload = {
    "banner": data
}

response = requests.patch("https://discord.com/api/v10/users/@me", headers=headers, json=payload)

if response.status_code == 200:
    print("Success.")
else:
    print(response.json())

Instructions

  • Put your Bot token inside the token variable.
  • Specify the path to your image file in the path variable. To make things easier, put the file in the same directory where the script is located.
  • Run the script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment