mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core] Fix loading of cogs on initial startup (#971)
This commit is contained in:
parent
5ae6fe2dda
commit
cf77eb2e47
@ -16,6 +16,8 @@ from redbot.core import i18n
|
|||||||
|
|
||||||
import redbot.cogs # Don't remove this line or core cogs won't load
|
import redbot.cogs # Don't remove this line or core cogs won't load
|
||||||
|
|
||||||
|
__all__ = ["find_spec", "Core"]
|
||||||
|
|
||||||
log = logging.getLogger("red")
|
log = logging.getLogger("red")
|
||||||
|
|
||||||
OWNER_DISCLAIMER = ("⚠ **Only** the person who is hosting Red should be "
|
OWNER_DISCLAIMER = ("⚠ **Only** the person who is hosting Red should be "
|
||||||
@ -23,6 +25,21 @@ OWNER_DISCLAIMER = ("⚠ **Only** the person who is hosting Red should be "
|
|||||||
"owner can access any data that is present on the host "
|
"owner can access any data that is present on the host "
|
||||||
"system.** ⚠")
|
"system.** ⚠")
|
||||||
|
|
||||||
|
|
||||||
|
async def find_spec(bot, cog_name: str):
|
||||||
|
try:
|
||||||
|
spec = await bot.cog_mgr.find_cog(cog_name)
|
||||||
|
except RuntimeError:
|
||||||
|
real_name = ".{}".format(cog_name)
|
||||||
|
try:
|
||||||
|
mod = importlib.import_module(real_name, package='redbot.cogs')
|
||||||
|
except ImportError:
|
||||||
|
spec = None
|
||||||
|
else:
|
||||||
|
spec = mod.__spec__
|
||||||
|
return spec
|
||||||
|
|
||||||
|
|
||||||
_ = i18n.CogI18n("Core", __file__)
|
_ = i18n.CogI18n("Core", __file__)
|
||||||
|
|
||||||
|
|
||||||
@ -33,17 +50,11 @@ class Core:
|
|||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def load(self, ctx, *, cog_name: str):
|
async def load(self, ctx, *, cog_name: str):
|
||||||
"""Loads a package"""
|
"""Loads a package"""
|
||||||
try:
|
spec = await find_spec(ctx.bot, cog_name)
|
||||||
spec = await ctx.bot.cog_mgr.find_cog(cog_name)
|
if spec is None:
|
||||||
except RuntimeError:
|
await ctx.send(_("No module by that name was found in any"
|
||||||
real_name = ".{}".format(cog_name)
|
" cog path."))
|
||||||
try:
|
return
|
||||||
mod = importlib.import_module(real_name, package='redbot.cogs')
|
|
||||||
except ImportError as e:
|
|
||||||
await ctx.send(_("No module by that name was found in any"
|
|
||||||
" cog path."))
|
|
||||||
return
|
|
||||||
spec = mod.__spec__
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ctx.bot.load_extension(spec)
|
ctx.bot.load_extension(spec)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from .sentry_setup import should_log
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from .utils.chat_formatting import inline
|
from .utils.chat_formatting import inline
|
||||||
|
from .core_commands import find_spec
|
||||||
|
|
||||||
log = logging.getLogger("red")
|
log = logging.getLogger("red")
|
||||||
sentry_log = logging.getLogger("red.sentry")
|
sentry_log = logging.getLogger("red.sentry")
|
||||||
@ -40,7 +41,7 @@ def init_events(bot, cli_flags):
|
|||||||
|
|
||||||
for package in packages:
|
for package in packages:
|
||||||
try:
|
try:
|
||||||
spec = await bot.cog_mgr.find_cog(package)
|
spec = await find_spec(bot, package)
|
||||||
bot.load_extension(spec)
|
bot.load_extension(spec)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception("Failed to load package {}".format(package),
|
log.exception("Failed to load package {}".format(package),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user