Python - discord.py,如何修复"事件循环已关闭"



我是一个编程初学者,我正在尝试启动我的第一个不和谐机器人,代码如下:

import discord
from discord.ext import commands 
client = commands.Bot(command_prefix = ".", intents = discord.Intents.all())
@client.event
async def on_ready():
print("BOT connected")
@client.command(pass_context = True)
async def hello(ctx):
await ctx.send("Hello. hey ")

TOKEN = "my token"
client.run(TOKEN)

和经过多次尝试运行后,我有一个巨大的可怕的错误:

"Traceback (most recent call last):
File "b:2serverdsmachines.py", line 17, in <module>
client.run("ODg2MjEyNTk5MjE2MjM0NTE2.YTyTzA.020rByPUfY8rDsw9iKDCi2jUZuM")
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 723, in run   
return future.result()
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000002203C0C0E50>
Traceback (most recent call last):
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
self.close()
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
self._check_closed()
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000002203C0C0E50>
Traceback (most recent call last):
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 746, in call_soon
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed
PS C:Usersыв> & C:/Users/ыв/AppData/Local/Programs/Python/Python39/python.exe b:/2/server/dsmachines.py
Traceback (most recent call last):
File "b:2serverdsmachines.py", line 17, in <module>
client.run(TOKEN)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 723, in run
return future.result()
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intenPS C:Usersыв> & C:/Users/ыв/AppData/Local/Programs/Python/Python39/python.exe b:/2/server/dsmachines.py
Traceback (most recent call last):
File "b:2serverdsmachines.py", line 16, in <module>
client.run(TOKEN)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 723, in run
return future.result()
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000267B2E00E50>
Traceback (most recent call last):
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
self.close()
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 746, in call_soon
self._check_closed()
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
PS C:Usersыв> & C:/Users/ыв/AppData/Local/Programs/Python/Python39/python.exe b:/2/server/dsmachines.py
Traceback (most recent call last):
File "b:2serverdsmachines.py", line 16, in <module>
client.run(TOKEN)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 723, in run
return future.result()
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https:ts instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000026F065D0E50>
Traceback (most recent call last):
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
self.close()
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 746, in call_soon
self._check_closed()
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
PS C:Usersыв> & C:/Users/ыв/AppData/Local/Programs/Python/Python39/python.exe b:/2/server/dsmachines.py
Traceback (most recent call last):
File "b:2serverdsmachines.py", line 16, in <module>
client.run(TOKEN)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 723, in run
return future.result()
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001A85999FE50>
Traceback (most recent call last):
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
self.close()
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
PS C:Usersыв> & C:/Users/ыв/AppData/Local/Programs/Python/Python39/python.exe b:/2/server/dsmachines.py
Traceback (most recent call last):
File "b:2serverdsmachines.py", line 16, in <module>
client.run(TOKEN)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 723, in run
return future.result()
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:UsersывAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001E2C8C4FE50>
Traceback (most recent call last):
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
self.close()
File "C:UsersывAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 746, in call_soon
self._check_closed()
File "C:UsersывAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed"
我不知道我需要做什么,我检查了很多论坛与类似的问题但他们都有一个错误,比如他们在client = commands.Bot(command_prefix = ".", intents = discord.Intents.all())中输入了一个小b,而不是大写的b或类似的东西,抱歉,伙计们,如果我在你们眼中看起来很蠢,但我就是找不到解决这个问题的方法提前感谢大家

从错误消息:

discord.errors。PrivilegedIntentsRequired:分片ID类中未显式启用的特权意图开发人员门户。建议去https://discord.com/developers/applications/并显式启用应用程序页面中的特权意图。如果不是这样如果可能,那么考虑禁用特权意图。

这意味着您正在请求尚未从开发人员页面启用的意图。您正在使用以下命令请求意图:client = commands.Bot(command_prefix = ".", intents = discord.Intents.all())。您可以从discord开发人员门户的bot选项卡启用它们(在bot的令牌代码下面)。对于discord.Intents.all(),启用两个特权网关意图

最新更新