问题
So I was trying out making a bot in Discord and I tried running my discord bot over Gitpod and it was able to run, but when I tried running it on pythonanywhere.com, I get this error:
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discordapp.com:443 ssl:default [Connect call failed ('162.159.134.233', 443)]
Here is a snippet of my code:
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)
Any help would be greatly appreciated.
回答1:
Free accounts on PythonAnywhere can't use the Discord websockets API, but you can use their HTTP-based one. Take a look at the forum post that explains how to do that.
来源:https://stackoverflow.com/questions/61229697/clientconnectorerror-cannot-connect-to-host-discordapp-com443-ssldefault-con