Question:
How i can fix this? i keep getting this runtimewarning and when I type ?help in discord bot says that command not found.
Error:
nexus.py:22: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension("cogs.help")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Repl link:
https://replit.com/@finnishdev/all-in-one-100
import os
import discord
from discord.ext import commands
from cogs.help import Help
from keep_alive import keep_alive
keep_alive()
bot = commands.Bot(
command_prefix="?", case_insensitive=True, intents=discord.Intents.all()
)
bot.remove_command("help")
@bot.event
async def on_ready():
print(f"Logged in as {bot.user.name}")
print(f"Bot ID: {bot.user.id}")
await bot.wait_until_ready()
try:
bot.load_extension("cogs.help")
print("Cog 'help' loaded successfully!")
except Exception as e:
print(f"Failed to load cog 'help': {e}")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.errors.CommandNotFound):
await ctx.send(
"The command you specified was not found. Type ?help to see all available"
" commands."
)
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send("You are missing a required argument.")
elif isinstance(error, commands.errors.MissingPermissions) or isinstance(
error, discord.Forbidden
):
await ctx.send("Sorry. You don't have the permission for that command.")
elif isinstance(error, commands.errors.CommandOnCooldown):
if ctx.command.name == "report":
await ctx.message.delete()
await ctx.author.send(
f"""Sorry, but we have made a cooldown to prevent the abuse of the command. Try again in {error.retry_after:,.2f} seconds.
If you want to report something before the cooldown is over or you made a report on accident then please contact a staff member and we will get it sorted out."""
)
else:
await ctx.send(
f"You need to wait {error.retry_after:,.2f} seconds before trying this"
" command again."
)
elif isinstance(error, commands.errors.MissingRole):
if ctx.command.name in [""]:
await ctx.send("You need premium to use this command")
else:
await ctx.send(f"An error occurred: {error}")
bot.run(os.environ["token"])
The error is saying that you must await bot.load_extension
. Since you’re already inside an async function (on_ready event) you just need to add the await
keyword.
try:
await bot.load_extension("cogs.help") # Add the await before the bot.load
4 Likes
Not working. Im still getting same runtimewarning
Can you show the full error message?
Okay, it seems I just got new error. Idk if my friend did something to code but now its saying this
You just need to change the port in this case, or even better, just let that Replit assign the port and erase the part where you specify the port in your keep_alive.py code.
def run():
app.run(host='0.0.0.0')
Can you get the full error message?
From the looks of it there seems to be no problem at all with the code.
Only error what i get is “failed to load cog…”
Since there is no traceback information I think it would be better you start configure logging into your application. Import the logging configuration in your nexus.py:
import logging
And configure the logging level
logging.basicConfig(level=logging.INFO, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s')
And the logging events in your on_ready
@bot.event
async def on_ready():
logging.info(f'Logged in as {bot.user.name} (ID: {bot.user.id})') #add this line
# the rest of your code
1 Like
Can you try test the bot without loading the ‘help’ cog to see if the error persists?
I removed it and no error. So problem is in import cog
So what should i do @WindLother?
Erase this part from your __init__.py
def setup(bot):
bot.add_cog(Help(bot))
bot.add_cog(Afk(bot))
bot.add_cog(Avatar(bot))
bot.add_cog(Dadjoke(bot))
bot.add_cog(Developers(bot))
bot.add_cog(MemberCount(bot))
bot.add_cog(Meme(bot))
bot.add_cog(Purge(bot))
bot.add_cog(Report(bot)
And change your nexus.py
a little
import os
import logging
import sys
import traceback # Since is not gerenerating any traceback import his so we can know the full error
import discord
from discord.ext import commands
from keep_alive import keep_alive
# Try add a list of cogs to be loaded (add this after all your events, before the def setup(bot)
initial_extensions = [
"cogs.help",
"cogs.afk",
"cogs.avatar",
"cogs.dadjoke",
"cogs.developers",
"cogs.membercount",
"cogs.meme",
"cogs.purge",
"cogs.report",
]
if __name__ == "__main__":
# Then load the cogs here
for extension in initial_extensions:
try:
bot.load_extension(extension)
except Exception as e:
print(f"Failed to load extension {extension}.", file=sys.stderr)
traceback.print_exc() # This will print the full traceback
keep_alive() # And move the keep_alive() to here
bot.run(os.environ["token"])
And remove all this part from your on_ready event:
try:
await bot.load_extension("cogs.help")
print("Cog 'help' loaded successfully!")
except Exception as e:
print(f"Failed to load cog 'help': {e}"
So the on_ready() event will look like this:
@bot.event
async def on_ready():
logging.info(f'Logged in as {bot.user.name} (ID: {bot.user.id})')
print(f'Logged in as {bot.user.name}')
print(f'Bot ID: {bot.user.id}')
await bot.change_presence(activity=discord.Game(name="COMMANDS OFFLINE"))
Try this changes and let me know.
Says this same error for every file.
I think I just did some simple mistake with bot function but idk
You did not insert the code in the order I told you. The part I told you to include goes to the bottom part after youir whole code and before the bot.run(os.environ["token"])
.
Oh sorry, I read your instruction wrong. I think I now did it right and got once again runtime warning + error in the image. Bot still saying that cmd not found.
Sry, im dump with cogs. But I dont want to give up with this