【发布时间】:2021-10-15 20:52:21
【问题描述】:
由于某种原因,当我尝试使用 PyPresence 设置与我的 Xbox Live 状态相同的 Discord 丰富状态时,但我一直收到错误消息 RuntimeWarning: coroutine 'BaseClient.read_output' was never awaited。
这是我的代码
import os
import asyncio
from aiohttp import ClientSession
from xbox.webapi.api.client import XboxLiveClient
from xbox.webapi.authentication.manager import AuthenticationManager
from xbox.webapi.authentication.models import OAuth2TokenResponse
from pypresence import Presence
import requests
import time
clientID = os.environ.get("CLIENT_ID")
clientSecret = os.environ.get("CLIENT_SECRET")
discordAppID = os.environ.get("DISCORD_APP_ID")
rpc = Presence(discordAppID)
rpc.connect()
async def async_main():
tokens_file = "./tokens.json"
async with ClientSession() as session:
authManager = AuthenticationManager(session, clientID, clientSecret, "")
with open(tokens_file, mode = "r") as f:
token = f.read()
authManager.oauth = OAuth2TokenResponse.parse_raw(token)
xblClient = XboxLiveClient(authManager)
rpc.update(state = "test state")
asyncio.run(async_main())
当我取出rpc.update(state="test state") 行时不会发生错误,所以我知道这是错误的原因,但我无法弄清楚为什么会导致错误以及如何修复它。
编辑:这也是RuntimeError: Cannot run the event loop while another loop is running
【问题讨论】:
标签: python async-await discord