ClientConnectorError:无法连接到主机discordapp.com:443 ssl:默认[连接调用失败('162.159.134.233',443)]

ivy*_*ivy 2 python-3.x pythonanywhere discord discord.py

所以我尝试在 Discord 中创建一个机器人,并尝试在 Gitpod 上运行我的 Discord 机器人,它能够运行,但是当我尝试在 pythonanywhere.com 上运行它时,我收到此错误:

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

这是我的代码片段:

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)
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

Fil*_*lip 5

PythonAnywhere 上的免费帐户无法使用 Discord websockets API,但您可以使用其基于 HTTP 的 API。查看解释如何执行此操作的论坛帖子。