#๐Ÿ”’ Hello, i am trying to implement cogs in my discord-py bot, but it doesnt work

64 messages ยท Page 1 of 1 (latest)

limber pendantBOT
#

@dire niche

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

haughty compass
#

show codes please

dire niche
#

sumn got deleted

#

whenever i attach the files

#

the ]y get deleted?

#

how can i fix that?

haughty compass
#

show me the codes

dire niche
#

wait

little frigate
#

!paste

limber pendantBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

dire niche
little frigate
#

it seems to me the load_extensions is never actually called?

dire niche
#

then where do i call it?
also, is there anything wrong with the cog itself?

haughty compass
#

do you need an example?

little frigate
#

no

dire niche
little frigate
#

the easiest way is to not use bot.run() but instead do it like this:

import asyncio

...

async def main():
    await load_extensions()
    
    async with bot:
        await bot.start(BOT_TOKEN)

asyncio.run(main()) # last line in your code, instead of bot.run()
haughty compass
little frigate
white robin
#

Also, you have a bot (not client) but you are using client.load_extension

little frigate
#

(true, that needs fixing)

dire niche
#

do i call main from on_ready?

#

oh ok lemme check

little frigate
#

no?

plain walrus
#

use the setup_hook

haughty compass
dire niche
#

ok, i changed it to look like this

#

python ```# LOADING COGS
async def load_extensions():
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
# cut off the .py from the file name
await bot.load_extension(f"cogs.{filename[:-3]}")

print(init_ext)
#END

async def main():
await load_extensions()

async with bot:
    await bot.start(BOT_TOKEN)

asyncio.run(main())```

#

is this correct?

little frigate
#

try it

#

(don't forget to import asyncio at the top if you haven't already)

dire niche
#

i did lol

haughty compass
dire niche
#

so, the cogs are not being loaded

haughty compass
little frigate
#

how do you know?

dire niche
#

i did a print

little frigate
#

try adding a print() in your setup functions in your cogs

dire niche
#

and the list came out empty

little frigate
#

i see

#

what exactly did you print?

dire niche
#

print(init_ext)

#

if you remember, i made one this one. and appended every cog to it

little frigate
#

no idea what that's even is... print in you load_extensions function instead

#

in the loop even.. just print the filename

#

and als print in you setup functions in your cog files

dire niche
plain walrus
#

just throw a ping command in ur cog and test if it works ๐Ÿ’€ or use the cog_load event

little frigate
#

give it nice text to print, so you know what you'r seeing

#

init_ext is just an empty list

#

you never use it for anything

#

that print is pointless and can be removed.

#

print in your load_extensions function instead like I explained.

dire niche
#

the name of the cog

little frigate
#

it means it can find it

#

go to you Greetings.py, and find the setup function at the bottom

#

print something in there as well e.g. print('setup called in', __file__)

haughty compass
limber pendantBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.