使用 python 进行不和谐存在时出错

errors while using python to do discord presence

所以我有这个代码

import psutil
from pypresence import Presence
import time

client_id = 787757685453  # Fake ID, put your real one here
RPC = Presence(client_id,pipe=0)  # Initialize the client class
RPC.connect() # Start the handshake loop


while True:  # The presence will stay on as long as the program is running
    cpu_per = round(psutil.cpu_percent(),1) # Get CPU Usage
    mem = psutil.virtual_memory()
    mem_per = round(psutil.virtual_memory().percent,1)
    print(RPC.update(details="RAM: "+str(mem_per)+"%", state="CPU: "+str(cpu_per)+"%"))  # Set the presence
    time.sleep(15) # Can only update rich presence every 15 seconds

当我 运行 它以 id 作为字符串时,错误是:

当我 运行 它不是字符串时它给我这个错误

所以我完全卸载了模块并使用了这段代码 我需要使用一个应用程序而不是文字客户端 ID 这是代码

import discord_rpc
import time
cid= "app id here"
if __name__ == '__main__':
    def readyCallback(current_user):
        print('Our user: {}'.format(current_user))

    def disconnectedCallback(codeno, codemsg):
        print('Disconnected from Discord rich presence RPC. Code {}: {}'.format(
            codeno, codemsg
        ))

    def errorCallback(errno, errmsg):
        print('An error occurred! Error {}: {}'.format(
            errno, errmsg
        ))

    # Note: 'event_name': callback
    callbacks = {
        'ready': readyCallback,
        'disconnected': disconnectedCallback,
        'error': errorCallback,
    }
    discord_rpc.initialize(cid, callbacks=callbacks, log=False)

    i = 0
    start = time.time()
    while i < 10:
        i += 1

        discord_rpc.update_presence(
            **{
                'details': "listening to",
                'start_timestamp': start,
                'large_image_key': 'default'
            }
        )
    while True:
        discord_rpc.update_connection()
        time.sleep(2)
        discord_rpc.run_callbacks()

    discord_rpc.shutdown()

编辑:我最终使用了这个只是因为 pycharm 不允许我使用 discord_rpc 而你需要做的就是将 id 设置为一个不和谐的应用程序 id