#self.clear_tiems() Not working

1 messages · Page 1 of 1 (latest)

golden plaza
#

I have a view that has a buttons I update pretty frequently to which I have to sometimes add or update buttons so i just clear_items then add them again then update the message but sometimes very randomly it just doesn't clear idky



            print(self.to_components)
            self.clear_items()
            print(self.to_components)

            self.poke_button()
            self.skill_button()
            self.ult_button()
            self.skip_button()
            print(self.to_components)

<bound method View.to_components of <MovesSelection timeout=1500 children=4>>
<bound method View.to_components of <MovesSelection timeout=1500 children=4>>
<bound method View.to_components of <MovesSelection timeout=1500 children=8>>
An error occurred:
Traceback (most recent call last):
  File "c:\Users\Hi\Documents\codes\Project Valor\Valor\bot_files\cogs\TitanDescent.py", line 6645, in update_buttons
    await self.message.edit(view=self)
  File "c:\Users\Hi\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\message.py", line 1630, in edit
    data = await self._state.http.edit_message(
  File "c:\Users\Hi\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 374, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In components.0.components: Must be between 1 and 5 in length.
#

I'm not sure what other code to give so just lmk, idk why this is happening

#

And no, there are no other functions that add these buttons that are being called while this is being run

golden plaza
#

And also if I try

        print(len(self.children))
        self.clear_items()
        print(len(self.children))

I do get 4 then 0 but for some reason this shows

print(self.to_components)

<bound method View.to_components of <MovesSelection timeout=1500 children=8>>
and then the error pops up

wispy chasm
#

if thats the question

golden plaza
#

I meant locally

#

The view itself before updating it

#

I did get it to work though

#

I think

#

But its just really weird

#

basically like, self.clear() should remove all items right from the view but for some reason it would not

wispy chasm
golden plaza
#

somehow

#

as u saw

#

If I printed the length of self.children it shows that all were removed

#

but the print(self.to_components) showed that somehow it was repopulated with 8

#

so the past 4 were not removed properly and 4 more got added

#

really really weird

wispy chasm
#

So the to components does not get reset but the children does

golden plaza
#

yes

wispy chasm
#

I guess it’s because the to components check from the message directly

#

I’ll check the code of py cord after

golden plaza
#

Alright

final drum
#

Why are you relying on the repr of a method lol

#

Actually call the method or print the children

final drum
#

So it is clearing

golden plaza
#

because if it is clearing it, I still get the error saying too many buttons

fluid lion
#

clear_items is a very simple function, so I find it hard to believe there is an issue here. py def clear_items(self) -> None: """Removes all items from the view.""" self.children.clear() self.__weights.clear()

golden plaza
#

But I did get it fixed pretty sure

#

what I changed was

#

before when I was editing the message sometimes if the view was not to be updated I would not pass the view and pass the other stuff to edit

#

all I did was remove those

#

and made update with view = None

#

if there is supposed to be no view

#

and now I'm not gettng that error anymore

final drum
#

Makes sense

golden plaza
#

so smth about that was making it weird

final drum
#

You can't send or edit to an empty view

golden plaza
#

hmmm that might be it, it just baffled me cause for some reason it worked sometimes