尝试在我的主机中运行我的机器人时出现 Discord.py 错误

时间:2021-01-16 11:32:00

标签: python python-3.x discord discord.py discord.py-rewrite

所以我尝试在我的主机上运行我的机器人,但它不断收到错误消息。我已经知道问题出在哪里,但我很困惑,因为当我在 Visual Studio 中运行我的代码时,它运行良好,但它只在主机中显示错误。代码是合法的,所以我需要一些帮助。

代码(它在一个齿轮内):

import discord
import random
import asyncio
from discord.ext import commands

class ppsize(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.command(aliases=['mypp', 'sizepp'])
    async def PPSize(self, ctx):
        responses = [ # Or values, however you want to name it
        'is 2cm.',
        'is 38cm.',
        'is 0cm.',
        'is too small to be measured.',
        '-16cm.',
        'bigger than a whole house.',
        '6cm.',
        'is 9cm',
        'is 13cm'
    ]
        pp = discord.Embed(title="Activating PP Size Measurement...!", description="Loading PP Size... This may take up to 5 seconds!")
        pp.set_image(url="https://tul.imgix.net/content/article/banana.jpg?auto=format,compress&w=1200&h=630&fit=crop")
        pp2 = discord.Embed(title="PP Size Measurement Has Been Activated!", description=random.choice(responses))
        pp2.set_image(url="https://tul.imgix.net/content/article/banana.jpg?auto=format,compress&w=1200&h=630&fit=crop")
        
        message = await ctx.send(embed=pp)
        await asyncio.sleep(5)
        await message.edit(embed=pp2)


def setup(client):
    client.add_cog(ppsize(client))

运行我的机器人后出现的错误:

Traceback (most recent call last):
  File "/home/container/aiohttp/connector.py", line 999, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
  File "/home/container/aiohttp/connector.py", line 865, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
  File "/home/container/aiohttp/resolver.py", line 31, in resolve
    infos = await self._loop.getaddrinfo(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 825, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/container/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/container/cogs/ppsize.py", line 29, in PPSize
    message = await ctx.send(embed=pp)
  File "/home/container/discord/abc.py", line 935, in send
    data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
  File "/home/container/discord/http.py", line 185, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/home/container/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/home/container/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/home/container/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/container/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/container/aiohttp/connector.py", line 1011, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discord.com:443 ssl:default [Temporary failure in name resolution]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/container/discord/ext/commands/bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "/home/container/discord/ext/commands/core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/container/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientConnectorError: Cannot connect to host discord.com:443 ssl:default [Temporary failure in name resolution]
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "ppsizre" is not found
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "PPsize" is not found

此外,我注意到它导致整个问题的部分是:

await asyncio.sleep(5)

那么有谁知道如何在不移除那部分的情况下修复它?

0 个答案:

没有答案