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