我正在尝试创建一个 on_ready 事件,询问我是否希望在我的客户端上有丰富的存在并输入“n”或“no”有效,但输入“y”或“yes”给我错误。我不确定是否有什么需要等待的,因为我对富人的存在相当陌生。
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\selma\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\selma\OneDrive\Desktop\Phoenix Bot\main.py", line 1651, in on_ready
await rpc.connect()
File "C:\Users\selma\AppData\Local\Programs\Python\Python39\lib\site-packages\pypresence\presence.py", line 43,
in connect
self.loop.run_until_complete(self.handshake())
File "C:\Users\selma\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 618, in run_until_complete
self._check_running()
File "C:\Users\selma\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 578, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
C:\Users\selma\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py:350: RuntimeWarning: coroutine 'BaseClient.handshake' was never awaited
pass
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
@client.event
async def on_ready():
print(f"{client.user.name} is ready.")
print(f"Started at: {datetime.datetime.utcnow()}")
print(f"Guilds: {len(client.guilds)}")
print("Do you want Rich Presence?(y/n)")
e = input("")
if e.lower() == "y":
rpc = Presence("804897816434180096")
await rpc.connect()
await rpc.update(
details="Invite and Vote Below",
large_image="phoenix",
large_text="Invite Phoenix Bot",
buttons = [
{"label": "Invite Phoenix Bot", "url": "https://discord.com/oauth2/authorize?client_id=804897816434180096&scope=bot%20applications.commands&permissions=8" }, {"label": "Vote For Phoenix Bot", "url": "https://top.gg/bot/804897816434180096/vote" }
]
)
elif e.lower() == "yes":
rpc = Presence("804897816434180096")
await rpc.connect()
await rpc.update(
details="Invite and Vote Below",
large_image="phoenix",
large_text="Invite Phoenix Bot",
buttons = [
{"label": "Invite Phoenix Bot", "url": "https://discord.com/oauth2/authorize?client_id=804897816434180096&scope=bot%20applications.commands&permissions=8" }, {"label": "Vote For Phoenix Bot", "url": "https://top.gg/bot/804897816434180096/vote" }
]
)
elif e.lower() == "n":
return print("Rich Presence is off")
elif e.lower() == "no":
return print("Rich Presence is off")
答案 0 :(得分:1)
我没有任何测试方法,但您可以尝试在调用 loop
时指定 Presence()
参数。像这样:
rpc = Presence("804897816434180096", loop=client.loop)
另外,请使用 or
语句而不是复制代码。
代替:
elif e.lower() == "n":
return print("Rich Presence is off")
elif e.lower() == "no":
return print("Rich Presence is off")
这样做:
elif e.lower() == "n" or e.lower() == "no":
return print("Rich Presence is off")
答案 1 :(得分:0)
快速浏览文档解决了这个问题,Presence().connect()
不是协程,即不需要等待。
rpc = Presence("804897816434180096")
rpc.connect()
rpc.update(**kwargs)