Reputation: 11
The buttons work after the command is sent, they show up on the embed, but once the bot restarts and I press the button that was on the previous embed, the discord app gives me an error that says interaction failed
, here's the discord.py code.
async def ticket(ctx, *title):
button = Button(label="Ready to start buying?",
style=discord.ButtonStyle.green)
guild = ctx.guild
dropperrole = discord.utils.get(guild.roles, id=1003171723207774218)
topdropperrole = discord.utils.get(guild.roles, id=1004989656137465917)
title = list(title)
title = " ".join(map(str, title))
view = View()
view.add_item(button)
async def button_callback(interaction):
await interaction.response.send_message("Creating channel...",
ephemeral=True)
await asyncio.sleep(3)
await interaction.edit_original_message(
content=
f"Channel successfully created #ticket-{(interaction.user.name).lower()} !"
)
overwrites = {
guild.default_role:
discord.PermissionOverwrite(view_channel=False),
interaction.user: discord.PermissionOverwrite(view_channel=True),
guild.me: discord.PermissionOverwrite(view_channel=True),
dropperrole: discord.PermissionOverwrite(view_channel=True),
topdropperrole: discord.PermissionOverwrite(view_channel=True)
}
chan = await ticket_category.create_text_channel(
f"ticket-{(interaction.user.name).lower()}", overwrites=overwrites)
id = discord.utils.get(
ctx.guild.channels,
name=f"ticket-{(interaction.user.name).lower()}")
await interaction.edit_original_message(
content=f"Channel successfully created {id.mention}!")
ccEmbed = discord.Embed(title=f"Hello {interaction.user.name}!",
color=0x2ecc71)
ccEmbed.add_field(
name="Ready to buy?",
value="Type `$dhc` to buy DHC, or `$buygen` to buy Gen! type `$fastpass` to buy fastpass, this allows you to skip all orders! To view prices, type `$prices`!",
inline=True)
ccEmbed.set_footer(text="discord.gg/dhcc | Rvse's Gen")
await chan.send(embed=ccEmbed)
button.callback = button_callback
Upvotes: 1
Views: 2562
Reputation: 59
You need to setup persistence so the bot will restart the view of your button when it launches. I think your are using Rapptz discord library? If so here is an example you can checkout: https://github.com/Rapptz/discord.py/blob/master/examples/views/persistent.py
Upvotes: 0