Skip to content

Instantly share code, notes, and snippets.

@bensonchow123
Created July 6, 2022 09:44
Show Gist options
  • Save bensonchow123/75bcae8ea75e5f16fc2d53360744790a to your computer and use it in GitHub Desktop.
Save bensonchow123/75bcae8ea75e5f16fc2d53360744790a to your computer and use it in GitHub Desktop.
Button not responding
class AdvertisementConfirmButton(ui.View):
def __init__(self, author, skybies_cost, num_messages):
super().__init__(timeout=10)
self.reply = None
self.author = author
self.skybies_cost = skybies_cost
self.num_messages = num_messages
async def on_timeout(self):
if self.reply.reference:
replied_to = self.reply.reference.resolved
await replied_to.delete()
await self.reply.delete()
async def interaction_check(self, interaction):
print("interaction check detected")
if self.author.id != interaction.user.id:
print("check is detected another person clicking button")
await interaction.response.send_message(
"This confirmation is not for you, you cannot confirm other's advertisement"
)
print("check have passed")
async def _status_embed(self, status, author):
if status == "accepted":
description = (
f"Message is sent!\n"
f"This is your {self.num_messages} message in the past 7 days,\n"
f"so {self.skybies_cost} skybies is deduced from your skybie count"
)
else:
description = (
f"Message is deleted, as you canceled your advertisement"
)
colour = 0x4bb543 if status == "accepted" else 0xff0033
status_embed = Embed(
description=description,
colour=colour
).set_author(
name=author.display_name,
icon_url=author.avatar.url
).set_thumbnail(
url="https://cdn.discordapp.com/attachments/850019796014858280/992247149767164026/promotion.png"
)
return status_embed
@ui.button(label="Confirm", style=ButtonStyle.success)
async def confirm(self, button: ui.Button, interaction: Interaction):
print("Interaction detected")
skybies = interaction.client.load_extension("Skybies")
print("cog loaded")
skybies._take_skybies(interaction.user, self.skybies_cost)
print("skybies taken")
status_embed = await self._status_embed("accepted", interaction.user)
print("embed created")
await interaction.response.send_message(
embed=status_embed,
ephemeral=True
)
print("embed sent")
await interaction.message.delete()
print("message deleted")
@ui.button(label="Cancel", style=ButtonStyle.danger,)
async def decline(self, button: ui.Button, interaction: Interaction):
if interaction.message.reference:
await interaction.message.reference.resolved.delete()
status_embed = await self._status_embed("canceled", interaction.user)
await interaction.response.send_message(
embed=status_embed,
ephemeral=True
)
await interaction.message.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment