TenType / discord-rich-presence

A lightweight and safe package for creating custom rich presences on Discord.
https://pypi.org/project/discord-rich-presence/
MIT License
8 stars 2 forks source link

How can i add buttons and images? #7

Closed B3ni15 closed 5 months ago

B3ni15 commented 5 months ago

Hello! How can i add buttons and images?

This is my code now:

from discordrp import Presence
import time
import tkinter as tk
import threading

client_id = "1214134857999982622"

# Discord Rich Presence beállítása
def set_discord_presence():
    with Presence(client_id) as presence:
        print("Connected")
        presence.set(
            {
                "state": "Teszt Játék",
                "details": "Summoner's Rift",
                "timestamps": {"start": int(time.time())}
            }
        )
        print("Presence updated")

        while True:
            time.sleep(15)

def open_window():
    window = tk.Tk()

    window.title("Üdvözöllek!")

    label = tk.Label(window, text="Hello, világ!")
    label.pack(padx=128, pady=128) 

    window.mainloop()

discord_thread = threading.Thread(target=set_discord_presence)
discord_thread.start()

open_window()
TenType commented 5 months ago

Hello!

Make sure that you upload your assets to the Rich Presence section of your app in the Discord Developer Portal.

Then, use the following template, replacing the large image key and small image key values with the names of your images.

with Presence(client_id) as presence:
    print("Connected")
    presence.set(
        {
            "state": "state",
            "details": "details",
            "timestamps": {"start": int(time.time())},
            "assets": {
                "large_image": "large image key",  # Replace this with the key of one of your assets
                "large_text": "large text hover", # Will show up when a user hovers over the image
                "small_image": "small image key",  # Replace this with the key of one of your assets
                "small_text": "small text hover", # Will show up when a user hovers over the image
            },
            "buttons": [
                {
                    "label": "label 1",
                    "url": "https://example.com",
                },
                {
                    "label": "label 2",
                    "url": "https://example.com",
                },
            ],
        }
    )
    print("Presence updated")

    while True:
        time.sleep(15)

Hope this helps! Let me know if you have any more questions.