#Persistent View With Member

1 messages · Page 1 of 1 (latest)

patent cairn
#

So I'm trying to make a persistent view with a added member and this is what I've tried

    @commands.slash_command()
    async def button(self, ctx: discord.ApplicationContext):
        member = ctx.author
        view = MyView(member)
        await ctx.respond(f"Press the button!")
        await ctx.send("View:", view=view)

    @commands.Cog.listener()
    async def on_ready(self):
        self.bot.add_view(MyView(self))

class MyView(discord.ui.View):
    def __init__(self, member):
        super().__init__(timeout=None) # timeout of the view must be set to None
        self.member = member

    @discord.ui.button(label="A button", custom_id="button-1", style=discord.ButtonStyle.primary, emoji=":sunglasses:") # the button has a custom_id set
    async def button_callback(self, button, interaction: discord.Interaction):
            await interaction.response.send_message(f"{self.member} sent you this view!", ephemeral=True)

It works when I use the command and press the button but it doesn't work when I restart the bot and use it again it returns
<test.Test object at 0x00000188F0C28280> sent you this view

reef vale
patent cairn
#

k

#

ok

patent cairn
# reef vale store the member as an ID and fetch/get the member
Ignoring exception in view <MyView timeout=None children=1> for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='A button' emoji=<PartialEmoji animated=False name='😎' id=None> row=None>:
Traceback (most recent call last):
  File "C:\Users\nxgge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ui\view.py", line 414, in _scheduled_task
    await item.callback(interaction)
  File "c:\Users\nxgge\OneDrive\Desktop\Discord Bots\Testing Bots\Slashing Slasher\test.py", line 27, in button_callback
    member = await self.bot.fetch_user(self.author)
  File "C:\Users\nxgge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 1597, in fetch_user
    data = await self.http.get_user(user_id)
  File "C:\Users\nxgge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\http.py", line 371, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In user_id: Value "<test.Test object at 0x000001529D93BE50>" is not snowflake.
#

the persistent view works it's just after I press the button after the bot restarts I get this

#

I also tried member = await self.bot.fetch_user(str(self.author))

reef vale
#

how are you storing it

dapper timber
#

You will almost certainly need. A storage system such as a database or the built in python storage system that I cant remember :/

patent cairn
#

ok

#

aiosqlite will work right?

dapper timber
#

^ thats the one I could not remember

patent cairn
#

ok thank you