我为 discord bot 创建了这个小示例代码,但是当我尝试连接时出现以下错误。
import discord
import os
from discord.ext import commands
from dotenv import load_dotenv
import urllib.request
import json
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='¿') # prefix del bot
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Streaming(name="Tutorial", url="http://www.twitch.tv/palmart69"))
print('bot listo')
@bot.command(pass_context=True)
async def ping(ctx):
await ctx.send("Pong!")
@bot.command(name='suma')
async def sumar(ctx, num1, num2):
response = int(num1) + int(num2)
await ctx.send(response)
bot.run(TOKEN)
--------ERROR------------------
Traceback (most recent call last):
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "C:\Users\Alvaro\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1081, in create_connection
transport, protocol = await self._create_connection_transport(
File "C:\Users\Alvaro\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1111, in _create_connection_transport
await waiter
File "C:\Users\Alvaro\AppData\Local\Programs\Python\Python39\lib\asyncio\sslproto.py", line 528, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Users\Alvaro\AppData\Local\Programs\Python\Python39\lib\asyncio\sslproto.py", line 188, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Users\Alvaro\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 944, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1123)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\main.py", line 31, in <module>
bot.run(TOKEN)
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\discord\client.py", line 718, in run
return future.result()
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\discord\client.py", line 697, in runner
await self.start(*args, **kwargs)
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\discord\client.py", line 660, in start
await self.login(*args, bot=bot)
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\discord\client.py", line 509, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\discord\http.py", line 293, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\discord\http.py", line 185, in request
async with self.__session.request(method, url, **kwargs) as r:
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\client.py", line 1117, in __aenter__
self._resp = await self._coro
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\client.py", line 520, in _request
conn = await self._connector.connect(
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\connector.py", line 1051, in _create_direct_connection
raise last_exc
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "C:\Users\Alvaro\PycharmProjects\bot-pruebas\venv\lib\site-packages\aiohttp\connector.py", line 971, in _wrap_create_connection
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host discord.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1123)')]
Process finished with exit code 1
我尝试了一些我在不同帖子中看到的东西(例如安装证书)。我是这个机器人世界的新手,所以我真的很感激这方面的一些帮助。先谢过。