假设我有一个简单的分歧。客户端代码:
import os
import discord
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
client = discord.Client(intents=intents)
@client.event
async def on_ready():
guild = None
for guild in client.guilds:
if guild.name == GUILD:
break
print(
f'{client.user} is connected to guild {guild.name} (id: {guild.id})'
)
client.run(TOKEN)
所以,当我停止代码时,我得到了一个异常:
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 751, in call_soon
self._check_closed()
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 515, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Process finished with exit code 0
它不会以任何方式影响代码和功能,但它非常令人讨厌。那么我如何正确断开/关闭连接?