【问题标题】:from config import get_config从配置导入get_config
【发布时间】:2023-01-30 10:04:46
【问题描述】:

我无法从config导入get_config,我不知道为什么 我的错误在哪里,我该如何解决这里是我的不和谐机器人脚本的一部分

from config import get_config

@bot.command()
async def Ping(ctx, address: str) -> None:
        """
        Performs a HTTP request to the specified address
        :param ctx: commands.Context
        :param address: Address to make request to
        :return: HTTP status code
        """
        if not address.startswith("http"):
            address = f"http://{address}"

        timeout = get_config("timeout")
        address = escape_mentions(address)

        async with aiohttp.ClientSession(
            timeout=aiohttp.ClientTimeout(total=timeout)
        ) as session:
            try:
                async with session.get(address) as res:
                    await ctx.reply(
                        f"Recieved response code: {res.status} ({res.reason})"
                    )
            except asyncio.TimeoutError:
                await ctx.reply(f"Request timed out after {timeout} seconds")
            except aiohttp.ClientError:
                await ctx.reply(f"Could not establish a connection to {address}")

错误:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'get_config' is not defined

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您可能缺少正确的 python 模块。尝试:

    pip install config
    

    【讨论】:

      猜你喜欢
      • 2021-10-12
      • 2021-07-01
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 2023-03-06
      • 1970-01-01
      相关资源
      最近更新 更多