ClientConnectorError: Cannot connect to host discordapp.com:443 ssl:default [Connect call failed ('162.159.134.233', 443)]

ClientConnectorError: Cannot connect to host discordapp.com:443 ssl:default [Connect call failed ('162.159.134.233', 443)]

所以我尝试在 Discord 中制作一个机器人,我尝试 运行在 Gitpod 上安装我的 Discord 机器人,它能够 运行,但是当我尝试 运行ning它在 pythonanywhere.com 上,我收到此错误:

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discordapp.com:443 ssl:default [Connect call failed ('162.159.134.233', 443)]

这是我的代码片段:

import discord
from discord.ext import commands
import json

with open("credentials.json") as creds:
    creds = json.loads(creds.read())
    TOKEN = creds["TOKEN"]

client = discord.Client()

class Bot(commands.Bot):
    def __init__(self):
        super(Bot, self).__init__(command_prefix="$", case_insensitive=True)
        self.pool = None

bot = Bot()

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user)
    print('------')

# calculate
@bot.command()
async def calculate(ctx):
    await ctx.send("foo")

bot.run(TOKEN)

如有任何帮助,我们将不胜感激。

PythonAnywhere 上的免费帐户不能使用 Discord websockets API,但您可以使用他们基于 HTTP 的。查看解释如何执行此操作的 forum post