本文介绍了ClientConnectorError:无法连接到主机discordapp.com:443 ssl:默认[连接呼叫失败('162.159.134.233',443)]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我尝试在Discord中制作一个bot,并尝试在Gitpod上运行我的discord bot,并且该bot能够运行,但是当我尝试在pythonanywhere.com上运行它时,出现此错误:
aiohttp.client_exceptions.ClientConnectorError:无法连接到主机discordapp.com:443 ssl:默认[连接呼叫失败('162.159.134.233',443)]
这是我的代码段:
导入不和谐从discord.ext导入命令导入json使用open("credentials.json")作为凭据:creds = json.loads(creds.read())令牌=凭证[令牌"]客户端= discord.Client()Bot类(commands.Bot):def __init __():超级(自动,自我).__init __(command_prefix ="$",case_insensitive = True)self.pool =无机器人= Bot()@ bot.event异步def on_ready():打印('登录为')打印(bot.user)打印(' - - - ')# 计算@ bot.command()异步def计算(ctx):等待ctx.send("foo")bot.run(令牌)
任何帮助将不胜感激.
解决方案
PythonAnywhere上的免费帐户无法使用Discord websockets API,但可以使用其基于HTTP的API.请参阅论坛帖子,其中介绍了如何执行此操作./p>
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.
解决方案
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.
这篇关于ClientConnectorError:无法连接到主机discordapp.com:443 ssl:默认[连接呼叫失败('162.159.134.233',443)]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!