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'```
#Help me (cog)
1 messages · Page 1 of 1 (latest)
saddly i can't, my host dosen't have a shell to run commands
nope
but im 100% i install py-cord
import os
os.system("pip freeze > pip.txt")
You could try something like that
lemme try
Which host do you use?
bot hosting
that doesnt narrow it down at all
yea, show it please
one sec.
check dm
no, post it here
sorry for my messy code, in future i will organize it
yea okay and where is your bot definition
also, please add py after the first three backticks so the code is properly highlighted
What do you mean
where is your bot = discord.Bot
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")
Don't ask about all the imports, i have to remove them
I think in ur cog
You need to put the class view at the top
And below the cog
And not the opposite
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))
In the other cog that is working, the view class is below the cog class ?
no i mean this one
class verify(commands.Cog):
def __init__(self, bot):
self.bot = bot
ideally your view class is not in a cog's file at all
and how can i do this? cuz on github or guide i don't find anything like that
just make another file
Here's the counter example.
ok
you can do like that :
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
oh, i think i can't do it cuz will messed up my code
or maybe i don't know how to fix it
do you know basic (object oriented) programming
you cant really make a bot without the basics
i can but i make my code very messy
In the code you sent
Just move the class of the view above the class of the cog
Yeah but the user need to input soemthing and then the input is send to view and the view need that input to work
then pass it to the view when you make it