Files
Syntrel/cogs/fun/coinflip.py

62 lines
2.0 KiB
Python
Raw Normal View History

2025-09-14 18:54:56 -04:00
import random
import discord
from discord.ext import commands
2025-11-02 23:32:52 -05:00
2025-09-14 18:54:56 -04:00
class Choice(discord.ui.View):
def __init__(self) -> None:
super().__init__()
self.value = None
@discord.ui.button(label="Heads", style=discord.ButtonStyle.primary)
2025-09-14 18:54:56 -04:00
async def confirm(
self, interaction: discord.Interaction, button: discord.ui.Button
) -> None:
self.value = "heads"
self.stop()
@discord.ui.button(label="Tails", style=discord.ButtonStyle.primary)
2025-09-14 18:54:56 -04:00
async def cancel(
self, interaction: discord.Interaction, button: discord.ui.Button
) -> None:
self.value = "tails"
self.stop()
2025-11-02 23:32:52 -05:00
def coinflip_command():
2025-09-14 18:54:56 -04:00
@commands.hybrid_command(
2025-11-02 23:32:52 -05:00
name="coinflip", description="Make a coin flip, but give your bet before."
2025-09-14 18:54:56 -04:00
)
async def coinflip(self, context):
2025-09-14 18:54:56 -04:00
buttons = Choice()
embed = discord.Embed(
2025-11-02 23:32:52 -05:00
title="Coinflip", description="What is your bet?", color=0x7289DA
)
embed.set_author(
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
)
2025-09-14 18:54:56 -04:00
message = await context.send(embed=embed, view=buttons)
await buttons.wait()
result = random.choice(["heads", "tails"])
if buttons.value == result:
embed = discord.Embed(
title="Coinflip",
2025-09-14 18:54:56 -04:00
description=f"Correct! You guessed `{buttons.value}` and I flipped the coin to `{result}`.",
color=0x00FF00,
2025-09-14 18:54:56 -04:00
)
2025-11-02 23:32:52 -05:00
embed.set_author(
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
)
2025-09-14 18:54:56 -04:00
else:
embed = discord.Embed(
title="Coinflip",
2025-09-14 18:54:56 -04:00
description=f"Woops! You guessed `{buttons.value}` and I flipped the coin to `{result}`, better luck next time!",
color=0xE02B2B,
)
2025-11-02 23:32:52 -05:00
embed.set_author(
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
)
2025-09-14 18:54:56 -04:00
await message.edit(embed=embed, view=None, content=None)
2025-11-02 23:32:52 -05:00
return coinflip