#Help me (cog)

1 messages · Page 1 of 1 (latest)

pulsar rose
#
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 790, in _load_from_module_spec
    setup(self)
  File "/home/container/cogs/verify.py", line 233, in setup
    bot.add_cog(verify(bot)) 
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 660, in add_cog
    cog = cog._inject(self)
          ^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 568, in _inject
    raise e
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 562, in _inject
    bot.add_command(command)
    ^^^^^^^^^^^^^^^
AttributeError: 'Bot' object has no attribute 'add_command'. Did you mean: 'all_commands'?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/container/main.py", line 33, in <module>
    bot.load_extension(f'cogs.{cog}')
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 912, in load_extension
    self._load_from_module_spec(spec, name)
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 795, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'cogs.verify' raised an error: AttributeError: 'Bot' object has no attribute 'add_command'```
#

Note that i have a await main(), idk if this help

#

If is need i will give the code

autumn matrix
#

do you have any add_command somewhere?

#

Can you show the pip list pls

pulsar rose
#

saddly i can't, my host dosen't have a shell to run commands

pulsar rose
pulsar rose
autumn matrix
#

You could try something like that

pulsar rose
#

lemme try

autumn matrix
#

Which host do you use?

pulsar rose
pulsar rose
verbal zealot
#

that doesnt narrow it down at all

verbal zealot
pulsar rose
#

one sec.

pulsar rose
verbal zealot
#

no, post it here

pulsar rose
#

ok

pulsar rose
verbal zealot
#

yea okay and where is your bot definition

#

also, please add py after the first three backticks so the code is properly highlighted

pulsar rose
verbal zealot
#

where is your bot = discord.Bot

pulsar rose
#

in main file

import os
import json
import time
import pytz
import random
import string
import discord
import asyncio
import requests
from discord import option
from datetime import datetime
from discord.embeds import Embed
from discord.ext import tasks, commands

intents = discord.Intents.default()
intents.messages = True
intents.members = True


bot = discord.Bot(intents=intents)

@bot.event
async def on_ready():
    print(f"Logged into discord api as: {bot.user}") # Logged into discord api as: user#0001


cogs_list = [
    'server_grup',
    'verify'
]

for cog in cogs_list:
    bot.load_extension(f'cogs.{cog}')

bot.run("XXX")
pulsar rose
austere flume
#

I think in ur cog

#

You need to put the class view at the top

#

And below the cog

#

And not the opposite

pulsar rose
# austere flume I think in ur cog

fr? i have a basic cog that don't do that much and is working, on the same structure, up the class and sown the
def setup(bot):
bot.add_cog(server(bot))

austere flume
pulsar rose
#

no i mean this one

class verify(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

verbal zealot
#

ideally your view class is not in a cog's file at all

pulsar rose
verbal zealot
#

just make another file

marble gladeBOT
#

Here's the counter example.

austere flume
#

Not that

#

I sent the wrong thing wait

pulsar rose
#

ok

austere flume
#
class Bot_Test_View(discord.ui.View):
    def __init__(self, bot, translator):
        super().__init__(timeout=None)
        self.bot: Lumabot = bot
        self.add_item(discord.ui.Button(label="test"))

class Bot_Test(commands.Cog):
    def __init__(self, bot):
        self.bot: Lumabot = bot

    @subcommand(f"bot")
    @commands.slash_command()
    async def test(self, ctx: discord.ApplicationContext):
        translator = get_translator(ctx)
        await ctx.respond(content="test", view=Bot_Test_View(self.bot, translator))

def setup(bot):
    bot.add_cog(Bot_Test(bot))
#

and not like that :

class Bot_Test(commands.Cog):
    def __init__(self, bot):
        self.bot: Lumabot = bot

    @subcommand(f"bot")
    @commands.slash_command()
    async def test(self, ctx: discord.ApplicationContext):
        translator = get_translator(ctx)
        await ctx.respond(content="test", view=Bot_Test_View(self.bot, translator))

class Bot_Test_View(discord.ui.View):
    def __init__(self, bot, translator):
        super().__init__(timeout=None)
        self.bot: Lumabot = bot
        self.add_item(discord.ui.Button(label="test"))

def setup(bot):
    bot.add_cog(Bot_Test(bot))
#

i think that's ur issue

pulsar rose
#

lemme try

#

hope i don't fail 😅

pulsar rose
pulsar rose
verbal zealot
#

do you know basic (object oriented) programming

#

you cant really make a bot without the basics

pulsar rose
#

i can but i make my code very messy

austere flume
#

Just move the class of the view above the class of the cog

pulsar rose
#

Yeah but the user need to input soemthing and then the input is send to view and the view need that input to work

verbal zealot
#

then pass it to the view when you make it