import discord from discord.ext import commands from discord.ui import Button, View import asyncio bot = commands.Bot(command_prefix="$") # Dictionary to hold giveaway data temporarily giveaways = {} # Create Giveaway Command @bot.command() async def giveaway(ctx, action: str, *args): if action == 'create': if len(args) < 4: await ctx.send("Please provide the correct arguments: $giveaway create <about> <time> <prize>") return title, about, time, prize = args[:4] try: time = int(time) # convert to integer for time duration except ValueError: await ctx.send("Time must be an integer (in minutes).") return giveaway_id = len(giveaways) + 1 giveaways[giveaway_id] = { "title": title, "about": about, "time": time, "prize": prize, "status": "ongoing" } await ctx.send(f"Giveaway Created: {title}\nTime: {time} minutes\nPrize: {prize}") await asyncio.sleep(time * 60) giveaways[giveaway_id]["status"] = "ended" await ctx.send(f"Giveaway Ended: {title}") elif action == 'delete': if len(args) < 1: await ctx.send("Please provide a giveaway ID to delete.") return giveaway_id = int(args[0]) if giveaway_id in giveaways: await ctx.send(f"Are you sure you want to delete giveaway {giveaway_id}? (Yes/No)") response = await bot.wait_for('message', check=lambda m: m.author == ctx.author) if response.content.lower() == 'yes': del giveaways[giveaway_id] await ctx.send(f"Giveaway {giveaway_id} has been deleted.") else: await ctx.send("Giveaway deletion cancelled.") else: await ctx.send("Giveaway ID not found.") elif action == 'edit': if len(args) < 1: await ctx.send("Please provide a giveaway ID to edit.") return giveaway_id = int(args[0]) if giveaway_id in giveaways: title = input("Enter new title: ") about = input("Enter new about: ") time = int(input("Enter new time in minutes: ")) prize = input("Enter new prize: ") giveaways[giveaway_id] = { "title": title, "about": about, "time": time, "prize": prize, "status": "ongoing" } await ctx.send(f"Giveaway {giveaway_id} has been updated.") else: await ctx.send("Giveaway ID not found.") else: await ctx.send("Invalid action. Use 'create', 'delete', or 'edit'.")