#Persistant Unique Views

1 messages · Page 1 of 1 (latest)

dusk spire
#

dont define the view class inside the command

plush dew
dusk spire
#

they should be like this

bot = ...

...

class MyView(...):
    ...

@bot.slash_command(...)
async def ...:
    ...
#

pass it to the view init

#

mhm

#

you could also just set the username in the custom id

#

if that makes stuff simpler

dusk spire
#

you need to bot.add_view outside the cmd

dusk spire
#

using this self.my_button.custom_id = username in the init

(replace my_button with the function name of your button

#

and in the callback, use button.custom_id to get the username

#

.rtfm button.custom

#

oof

dusk spire
#

Oh hmm

#

I just realised this won't work

#

Can you have the label as the username?

dusk spire
#

Oof. Then you would need a db

dusk spire
#

Hmm so store a reference of username with either custom id or message id

slim spire
#

I don’t know if this will help. My views were not persistent. But you save the message ID of the view that you send (along with any relevant state information). Upon restart, edit the message with a new View. You don’t need a DB for this. Assuming the data saved is just message IDs, you can probably get away with just pickling the message IDs that you need to edit with a new view upon restart. (I’m sure someone will cry foul and say always use databases to store data, but examine what the most appropriate solution is for your case - all the db overhead might not be needed.)

#

If this isn’t a valid solution, let me know why. I might need to understand the problem more.

steep heron
#

did your issue get solved?