Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

python - Discord.py error while trying to run my bot in my host

So I've tried running my bot in my host and it keeps getting an Error. I already know where the problem but I'm confused because when I run my code in Visual Studio it runs fine but it only shows an Error in the host. The code is legit the same so I will need some help with it.

The code(It's inside a cog):

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))

The Error I get after running my bot:

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

Also the part that I've noticed it makes this whole problem is:

await asyncio.sleep(5)

So does anyone know how to fix it without removing that part?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...