#on_ready listener not being called.

1 messages ยท Page 1 of 1 (latest)

smoky crow
worn cloak
smoky crow
#

same

#

I gave up

#

doing my stuff in the init with self.bot.loop.create_task

raven pulsar
#

Are you trying to put "on_ready" in a cog?
Sorry, still having trouble understanding English :/

#

And the worry is that in the Cog it is not called? Is that it?

#

Is your cog properly loaded? @worn cloak

worn cloak
#

Oh I found a workaround by moving the listener somewhere else. Not optimal, but it functions.

raven pulsar
worn cloak
raven pulsar
#

Okay
Here is the minimum code that works

main.py

import discord

bot = discord.Bot()

bot.load_extension("cogs.cog")
    
bot.run("")

cogs/cog.py

from discord.ext import commands

class onReady(commands.Cog):
   
    def __init__(self, bot):
        self.bot = bot
        
    @commands.Cog.listener()
    async def on_ready(self):
        print("[System] The bot is now online")
        

def setup(bot):
    bot.add_cog(onReady(bot))

If this gives you an idea, good game! ๐Ÿ™‚

worn cloak
#

Okay, so I'll explain the problem I'm having here at the top then recap again at the bottom for those of you brave enough to read all of my code. Giggle

From what I can tell, my bot is calling on_ready from the @Bot.event decorator, but not the @commands.Cog.listener decorator. Let me break down how I have this set up.

Here's my bot instance, pretty straightforward.

class FroggeBot(Bot):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.frogge_guilds = []
        self.error_channel = 974493350919045190```
#

Here's my main.py

bot = FroggeBot(
    command_prefix = ">>",
    intents = discord.Intents.all(),
    owner_id = os.getenv("ALLEGRO"),
    case_insensitive = True
)

######################################################################
@bot.event
async def on_ready():
    print("FroggeBot Online!")
    await change_status.start()

######################################################################
@tasks.loop(hours=2)
async def change_status():
    await bot.change_presence(activity=discord.Game(next(statuses)))

######################################################################

for filename in os.listdir("./cogs"):
    if filename.endswith(".py") and filename != "__init__.py":
        bot.load_extension(f"cogs.{filename[:-3]}")

######################################################################

bot.run(os.getenv("DISCORD_TOKEN"))```
As far as I can tell it's pretty standard.
#

Now here's the issue. That all runs fine. ๐Ÿ‘Œ๐Ÿป Looks great. BUT, in one of my cogs, I have this, and it is NOT being called.

class Internal(Cog):
    def __init__(self, bot: FroggeBot):
        self.bot: FroggeBot = bot

######################################################################
    @commands.Cog.listener("on_ready")
    async def load_guilds(self) -> None:
        """Loads all special FroggeBot config data for each guild."""

        # Iterate through and perform a query for each guild's ID number.
        for guild in self.bot.guilds:
            # Assign values into an object.
            print("====================")
            print(f"Loading: {guild.name} || ID: {guild.id}")

            frogge_guild = await GuildData.load(self.bot, guild=guild)

            print("Success!")

            # Add to the bot
            self.bot.frogge_guilds.append(frogge_guild)

        # Confirm guild load.
        print("=================================")
        print("All guilds loaded successfully...")

        return```
This just *isn't being called* for some reason and for the life of me I can't figure out why.

I stripped the bot down to it's bare bones components in a new temporary file. Literally only the essentials to run, and it still isn't calling `on_ready` from the `@commands.Cog.listener` decorator. I dunno, I'm stumped.
calm knoll
#

so for cogs, you might want to run it like this:

class Internal(Cog):
  def __init__(self, bot: FroggeBot):
    self.bot: FroggeBot = bot

  @commands.Cog.listener()
  async def on_ready(ctx):
    pass

terse aspen
#

maybe u need write on_ready in async def, not in decorator, ex ^

calm knoll
#

^

terse aspen
#

async def on_ready(self)

worn cloak
#

Testing now ^.^

worn cloak
#

That totally made sense to me lol

worn cloak
#

on_ready listener not being called.