Making A Discord Bot In Python (Part 4: Cogs)

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ธ.ค. 2024

ความคิดเห็น • 40

  • @Fluffyscratch
    @Fluffyscratch 25 วันที่ผ่านมา +1

    I added a new file in the cogs folder and coded a command, but when I start my main script it says that Ping.py is already loaded and it won't work, can you help me please ?

  • @Odd-Variety
    @Odd-Variety ปีที่แล้ว

    Thanks man a lot i was strugling in creating cogs and your video solve all my issues in this regards.

  • @paradoxial7665
    @paradoxial7665  2 ปีที่แล้ว +3

    Like my videos? Want to see more Discord.py content? Need help with your bot's code? Well what are you waiting for? Subscribe and enable notifications today! And don't forget to join my Discord Server! discord.com/invite/XcHQz8RaWJ

  • @armorman3005
    @armorman3005 ปีที่แล้ว

    Thanks. I saw an outdated tutorial about cogs that was made before the code was made asynchronous and was wondering why nothing worked. You helped alot.

    • @Shreel-001
      @Shreel-001 ปีที่แล้ว

      hi could u help me out

    • @armorman3005
      @armorman3005 ปีที่แล้ว

      @@Shreel-001 sure, what do you need

    • @Shreel-001
      @Shreel-001 ปีที่แล้ว

      it whowsme some kid of error you can check below@@armorman3005
      Traceback (most recent call last):
      File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\bot.py", line 941, in _load_from_module_spec
      setup = getattr(lib, 'setup')
      AttributeError: module 'cogs.Ping' has no attribute 'setup'
      During handling of the above exception, another exception occurred:
      Traceback (most recent call last):
      File "c:\Users\Administrator\Desktop\Python bot\bot.py", line 22, in
      asyncio.run(bot())
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio
      unners.py", line 44, in run
      return loop.run_until_complete(main)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64_qbz5n2kfra8p0\lib\asyncio\baseevents.py", line 649, in run_until_complete
      return future.result()
      File "c:\Users\Administrator\Desktop\Python bot\bot.py", line 19, in bot
      await load()
      File "c:\Users\Administrator\Desktop\Python bot\bot.py", line 15, in load
      await client.load_extension(f"cogs.{filename[:-3]}")
      File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\bot.py", line 1013, in load_extension
      await self._load_from_module_spec(spec, name)
      File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\bot.py", line 944, in _load_from_module_spec
      raise errors.NoEntryPointError(key)
      discord.ext.commands.errors.NoEntryPointError: Extension 'cogs.Ping' has no 'setup' function.

  • @ainnunhere
    @ainnunhere ปีที่แล้ว +1

    Doesn’t do anything for me it doesn’t load my bot idk why

  • @imthesrpina
    @imthesrpina ปีที่แล้ว

    thanks

  • @volefy
    @volefy 11 หลายเดือนก่อน

    it raised an error saying asyncio is not defined?

  • @mhatyi
    @mhatyi ปีที่แล้ว

    For me it sais the system doesnt find the path to ' ./cogs ' . What do I do?

  • @BestEli
    @BestEli ปีที่แล้ว +5

    whats the point of cogs?

    • @fipium
      @fipium ปีที่แล้ว +2

      im not an expert and i am still learning, but from my general understanding, cogs are a way to not only organize and sort your commands and other stuff, but i believe it allows you to edit the commands and reload the cogs without having to restart the bot entirely.

    • @nwchef
      @nwchef ปีที่แล้ว

      @@fipium do u think i should start learning and using them from the start when making a bot

    • @fipium
      @fipium ปีที่แล้ว

      @@nwchef from my understanding, cogs allow you to make changes and i think add new commands and code without having to completely restart the entire bot. if i understand that correctly, then yes absolutely worth to learn. itll also allow your code to be more organized and clean

  • @Racovik_
    @Racovik_ ปีที่แล้ว +3

    my bot does not respond to commands

  • @strawhatonpc4008
    @strawhatonpc4008 ปีที่แล้ว +3

    It says “./cogs” not found

    • @ooogaboooga8065
      @ooogaboooga8065 ปีที่แล้ว

      Try just cogs

    • @tacocat8829
      @tacocat8829 ปีที่แล้ว

      I changed mine to include the name of the file that contains the project: "./Folder/cogs"

  • @rowella7807
    @rowella7807 ปีที่แล้ว

    and we're gonna type in commands.cog.. and we're gonna type in DEATH 7:24

  • @Rustanovich
    @Rustanovich 8 หลายเดือนก่อน

    bot doesn't responding

  • @vip_bimmervip_bimmer8033
    @vip_bimmervip_bimmer8033 ปีที่แล้ว

    How should can I forward the original messages into a string?

  • @ramosswq
    @ramosswq 2 ปีที่แล้ว

    How do I use app commands and cogs

  • @bigtomDW
    @bigtomDW ปีที่แล้ว

    so to be clear COGS is another way of doing OOP within the discord module?

    • @paradoxial7665
      @paradoxial7665  ปีที่แล้ว +2

      You could... But it’s main function is just to offer clean organization of your commands, events, other code, etc…

  • @turtlebear4900
    @turtlebear4900 2 ปีที่แล้ว

    does it matter where I put each @ code? like should it be before my commands or like on the bottom?

    • @HDisky
      @HDisky ปีที่แล้ว

      @ ALWAYS has to be at top before "async def function():" my man

  • @Cheesyass8755
    @Cheesyass8755 2 ปีที่แล้ว

    I am using 2 cogs what should i do to load both of them 🙁🙁

    • @paradoxial7665
      @paradoxial7665  2 ปีที่แล้ว +1

      if both of the cog files end with ".py" AND they are set up how they are supposed to be, then python along with discord.py will load both of them up!

  • @anamzakir-gi3zc
    @anamzakir-gi3zc ปีที่แล้ว

    im the 800th subscriber

  • @dorukaltan4264
    @dorukaltan4264 ปีที่แล้ว +1

    l cant see command can you help me pleas

  • @omerakbu1t
    @omerakbu1t ปีที่แล้ว +2

    i get that error:
    File main.py, line 20, in main
    async with bot:
    TypeError: 'Bot' object does not support the asynchronous context manager protocol

    • @DaRealBlueCow
      @DaRealBlueCow ปีที่แล้ว +1

      same here, idk how to fix it

  • @walanyo480
    @walanyo480 ปีที่แล้ว +3

    I actually understand everything in the video, but i keep on getting: ModuleNotFoundError: No module named 'cogs'
    My code (thats relevant):
    async def load():
    for filename in os.listdir("./cogs"):
    if filename.endswith(".py"):
    print(filename)
    print(f"cogs.{filename[:-3]}")
    await client.load_extension(f"cogs.{filename[:-3]}") #ERROR ON THIS LINE
    # print(filename[:-3], "has loaded")
    A couple of other ppl have had this as well, would be helpful if you responded :)

    • @screamlaps7857
      @screamlaps7857 ปีที่แล้ว

      still need help?

    • @Akkkikkoo
      @Akkkikkoo ปีที่แล้ว

      @@screamlaps7857 yes

    • @screamlaps7857
      @screamlaps7857 ปีที่แล้ว

      @@Akkkikkoo you need to write not only the cogs folder .you need to write the folder where the cogs folder is in too, like this: for filename in os.listdir(".\discord_bot\cogs"):

    • @NightcorePartyMusic
      @NightcorePartyMusic หลายเดือนก่อน

      ​@@screamlaps7857ily man that helped a lot❤