#CommandInvokeError in (seemingly) random times

1 messages · Page 1 of 1 (latest)

languid bluff
#

Hi! I have the following code in the pregame.py cog:

class PregameCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.utilities = self.bot.get_cog("UtilitiesCog")

    @commands.command()
    async def newgame(self, ctx):
        ...
        if self.utilities.get_config_item('status') == 'on':
        ...

The utilities cog has this:

class UtilitiesCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    def get_config_item(self, key):
        state = self.read_game_state()
        return state[key]

I get this error:

   ...
   if self.utilities.get_config_item('status') == 'on':
AttributeError: 'NoneType' object has no attribute 'get_config_item'

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

Traceback (most recent call last):
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 347, in invoke
   await ctx.command.invoke(ctx)
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/core.py", line 950, in invoke
   await injected(*ctx.args, **ctx.kwargs)
 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/core.py", line 187, in wrapped
   raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'get_config_item'

I don't know what's causing the error, and sometimes it doesn't happen. Sometimes it stops happening and works correctly when I edit one of the involved files (any kind of edit apparently? but not always?) then save and reload the cogs. But as soon as the bot is restarted, the error appears again. I will appreciate any help because I've spent an hour trying to figure out this one and I'm no further than in the beginning 😅

I'm using the 2.5.0rc5 version.

quiet geode
#

"NoneType", read the error ;3

languid bluff
#

I don't know what that means. The UtilitiesCog is defined and loaded as part of the main script, so why does it return NoneType?

proven pond
#

Are you loading your utilities cog before that cog?

languid bluff
#

oooh it's order-sensitive? Ok, let me test

#

you're my hero, I think that was it. I have another error now but pretty sure it's unrelated. Thank you so much!

quiet geode
#

.close

compact ravenBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @thorny path.

Backup bot: </solved:1109625445990793246> (or .solved) with @compact raven.