#on_ready listener not being called.
1 messages ยท Page 1 of 1 (latest)
Oh gosh, I don't think I ever quite figured out the specific issue. What's your situation look like?
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
Oh I found a workaround by moving the listener somewhere else. Not optimal, but it functions.
I can take the time to help you make it work the way you wanted it to. A little challenge that interests me ๐
Honestly it's been so long since the original post that the issue is really a non-issue anymore. Once I got it working I mentally marked it as fixed ahaha
Okay
Here is the minimum code that works
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! ๐
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. 
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.
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
maybe u need write on_ready in async def, not in decorator, ex ^
^
async def on_ready(self)
Testing now ^.^
Hmm, it's still not getting called. On a whim, I checked and the bot is accepting commands. So the issue is happening somewhere between the "real" on_ready and the subsequent listened on_ready
That totally made sense to me lol
on_ready listener not being called.