mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
style: new code layout
This commit is contained in:
67
cogs/fun/coinflip.py
Normal file
67
cogs/fun/coinflip.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
|
||||
Description:
|
||||
🐍 A simple template to start to code your own and personalized Discord bot in Python
|
||||
|
||||
Version: 6.4.0
|
||||
"""
|
||||
|
||||
import random
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
|
||||
class Choice(discord.ui.View):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.value = None
|
||||
|
||||
@discord.ui.button(label="Heads", style=discord.ButtonStyle.blurple)
|
||||
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.blurple)
|
||||
async def cancel(
|
||||
self, interaction: discord.Interaction, button: discord.ui.Button
|
||||
) -> None:
|
||||
self.value = "tails"
|
||||
self.stop()
|
||||
|
||||
|
||||
class CoinFlip(commands.Cog, name="coinflip"):
|
||||
def __init__(self, bot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@commands.hybrid_command(
|
||||
name="coinflip", description="Make a coin flip, but give your bet before."
|
||||
)
|
||||
async def coinflip(self, context: Context) -> None:
|
||||
"""
|
||||
Make a coin flip, but give your bet before.
|
||||
|
||||
:param context: The hybrid command context.
|
||||
"""
|
||||
buttons = Choice()
|
||||
embed = discord.Embed(description="What is your bet?", color=0xBEBEFE)
|
||||
message = await context.send(embed=embed, view=buttons)
|
||||
await buttons.wait()
|
||||
result = random.choice(["heads", "tails"])
|
||||
if buttons.value == result:
|
||||
embed = discord.Embed(
|
||||
description=f"Correct! You guessed `{buttons.value}` and I flipped the coin to `{result}`.",
|
||||
color=0xBEBEFE,
|
||||
)
|
||||
else:
|
||||
embed = discord.Embed(
|
||||
description=f"Woops! You guessed `{buttons.value}` and I flipped the coin to `{result}`, better luck next time!",
|
||||
color=0xE02B2B,
|
||||
)
|
||||
await message.edit(embed=embed, view=None, content=None)
|
||||
|
||||
|
||||
async def setup(bot) -> None:
|
||||
await bot.add_cog(CoinFlip(bot))
|
||||
Reference in New Issue
Block a user