【发布时间】: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