#AttributeError: 'NoneType' object has no attribute 'bot'

1 messages · Page 1 of 1 (latest)

spring berry
#
class ClanProfileCog(commands.Cog):
    def __init__(self, bot: commands.Bot):
        self.bot = bot
        main_command = bot.get_slash_command("clan")
        assert isinstance(main_command, commands.InvokableSlashCommand)
        
        set_placeholder_parents(self, main_command)
        
    @staticmethod
    def group(data: list, group_size: int) -> list:
        for i in range(0, len(data), group_size):
            yield data[i:i + group_size]
class ProfileClanView(disnake.ui.View):
    def __init__(self, inter, bot):
        super().__init__(timeout=10)
        self.inter = inter
        self.bot = bot

# ...

    async def on_timeout(self):
        try: 
            message = self.bot.get_message(await self.inter.original_message().id)
            for item in message.children:
                item.disabled = True
            await self.inter.edit_original_message(view=self) 
            return await super().on_timeout()
        except disnake.NotFound:
            pass```
```py
    @command_placeholder(commands.SubCommand, name="profile", description = "...")
    async def clan_profile(self, inter : disnake.ApplicationCommandInteraction):

# ...

await inter.send(inter.author.mention, embed=embed, view=ProfileClanView(inter, self.bot))

ERROR: https://paste.disnake.dev/?id=1699796082067101&language=python

#

my problem is that I want to create a timeout that disables all buttons, but I want to disable the buttons that are under(with) the message, and not those that are related to the class

calm cedar
#

what is command_placeholder

spring berry
#

What I mean: I ve a class AncClass() there are my buttons, then while sending a message I set view = AncClass(), but in case I changed view and timeout will come, it will make AncClass buttons disabled only

spring berry
#

I don't think something wrong with it

calm cedar
#

incorrect function wrapping

#

use functools.wraps(original_function)

spring berry
#

For subcommand creating if main cmd in another cog

#

What should I do

spring berry
spring berry
#

@woven plaza your snippet is "eating" self?

woven plaza
spring berry
#

Okay, thanks

woven plaza
#

could very well be the case, as I don't think we ever set <command>.cog

spring berry
#

Could it be fixed some way?

woven plaza
#

yeah should be fairly easy

spring berry
#

I can't imagine how, can you give a hint?

woven plaza
#

easiest way would probably be to change

-     def __get__(self, instance: typing.Optional[object], owner: type):
+     def __get__(self, instance: typing.Optional[commands.Cog], owner: type):
          if not instance:
              return self

          # set_parent wasn't used yet, can't return command so just error.
          if not self.command:
              raise RuntimeError(
                  f"Must first set a subcommand(group) for function {self.func.__name__}."
              )

+         self.command.cog = instance
          return self.command
#

in CommandWrapperDescriptor.__get__, that is

#

if that doesn't work, lemme know

spring berry
#

okay, a bunch of thanks

spring berry
#

It isn't working fine or I use it incorrect way

spring berry
#

I don't know how to create commands with spaces another way

#

And one more question: how can I create a timeout which will disable the message component even they're not related to the class

spring berry
#

@woven plaza

hmm, I have doubts about several issues: a) is there a way to create a slash command with a space without using a subcommand? or how to do this rationally if the main command is in another cog. b) is there a way to create a timeout that will disable all buttons with the message, I mean a timeout that will not only turn the buttons of its class into disabled, but also those that will be with the message at that time (another view). I came up with the idea in the body of on_timeout to receive a message object by ID, and then change it, is this correct? I hope I explained clearly

#
from disnake.ext.commands import Cog, slash_command

from .a import A

class B(Cog):
    @A.test_cmd.sub_command()
    async def boo(self, inter):
        ... 

Hmm, more and more questions there...

woven plaza
#

is there a way to create a slash command with a space without using a subcommand?
nope

spring berry
#

Then the only way is to create all sub commands in one certain file where my main command situated?

#

Just import commands functions and * from their files to use

woven plaza
#

mm yeah cogs just come with too many problems imo

#

there's essentially no clean way to do it with cogs

spring berry
#

Everything will have their own troubles

#

But what about timeout

#

Only fetching message to do that?

woven plaza
#

you'd probably have to implement something manually if you're going to keep track of a global timeout over multiple views

spring berry
#
async def on_timeout(self):
        try: 
            message = self.bot.get_message(await self.inter.original_message().id)
            for item in message.children:
                item.disabled = True
            await self.inter.edit_original_message(view=self) 
            return await super().on_timeout()
        except disnake.NotFound:
            pass```

I got something like this, probably it's a good solution?
woven plaza
#

if it works for your usecase it's fine

spring berry
#

Okay, thank you very much

woven plaza
#

yeah tbh there's too much wacky stuff going on under the hood with cogs so it's kinda hard to figure out why this isn't working

#

welp at least this reminded me that I need to finish my pr that adds support for this to ext-plugins

spring berry
#

Everyone is waiting for it)

#

I solved the subcommand problem using relative import

#

Thanks a lot

tall carbonBOT
#
Solved!

Marked the thread as solved. If your question has not been answered, please open a new thread in #1019642966526140566.