#๐ Hello, i am trying to implement cogs in my discord-py bot, but it doesnt work
64 messages ยท Page 1 of 1 (latest)
@dire niche
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.
show codes please
sumn got deleted
whenever i attach the files
the ]y get deleted?
how can i fix that?
show me the codes
wait
!paste
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.
it seems to me the load_extensions is never actually called?
then where do i call it?
also, is there anything wrong with the cog itself?
set the main.py to read .py files in the "cogs" folder
do you need an example?
no
can u show me how to implement it in my code?
no, cog is right.
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()
wont work ig, i tried it sum months ago and didnt worked for me but idk
pretty sure I tried it like that recently and it worked fine. also it's in the docs
Also, you have a bot (not client) but you are using client.load_extension
(true, that needs fixing)
no?
use the setup_hook
change
await client.load_extension(f"cogs.{filename[:-3]}")
to:
await bot.load_extension(f"cogs.{filename[:-3]}")
and try it again.
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?
i did lol
try it now
so, the cogs are not being loaded
hm
how do you know?
i did a print
try adding a print() in your setup functions in your cogs
and the list came out empty
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
heres the main.py https://paste.pythondiscord.com/5P6A
just throw a ping command in ur cog and test if it works ๐ or use the cog_load event
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.
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__)
works now?
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.