python 2&3的discord丰富的状态库
discord-rpc.p的Python项目详细描述
不协调rpc.py
A Discord RPC library for Python 2 & 3.
安装
使用pip
对于最新的稳定版本:
pip install discord-rpc.py
对于最新的开发版本:
gitclonehttps://gitlab.com/somberdemise/discord-rpc.pycddiscord.pypython-mpipinstall-U.
示例
importdiscord_rpcimporttimeif__name__=='__main__':defreadyCallback(current_user):print('Our user: {}'.format(current_user))defdisconnectedCallback(codeno,codemsg):print('Disconnected from Discord rich presence RPC. Code {}: {}'.format(codeno,codemsg))deferrorCallback(errno,errmsg):print('An error occurred! Error {}: {}'.format(errno,errmsg))# Note: 'event_name': callbackcallbacks={'ready':readyCallback,'disconnected':disconnectedCallback,'error':errorCallback,}discord_rpc.initialize('token',callbacks=callbacks,log=False)i=0start=time.time()whilei<10:i+=1discord_rpc.update_presence(**{'details':'Iteration # {}'.format(i),'start_timestamp':start,'large_image_key':'default'})discord_rpc.update_connection()time.sleep(2)discord_rpc.run_callbacks()discord_rpc.shutdown()