如何解决使用 python 进行不和谐存在时的错误
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。