Files
Xalos/cogs/polls.py
2025-10-06 14:20:28 +02:00

54 lines
2.2 KiB
Python

import discord
from discord.ext import commands
from discord import app_commands
class Polls(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
# Emojis für bis zu 20 Optionen
self.poll_emojis = [
"🇦", "🇧", "🇨", "🇩", "🇪", "🇫", "🇬", "🇭", "🇮", "🇯",
"🇰", "🇱", "🇲", "🇳", "🇴", "🇵", "🇶", "🇷", "🇸", "🇹"
]
@app_commands.command(name="poll", description="Erstellt eine einfache Umfrage.")
@app_commands.describe(
question="Die Frage der Umfrage.",
options="Die Antwortmöglichkeiten, getrennt durch ein Semikolon (;)."
)
async def poll(self, interaction: discord.Interaction, question: str, options: str):
"""Erstellt eine Umfrage mit Reaktionen."""
# Trenne die Optionen am Semikolon
split_options = [opt.strip() for opt in options.split(';')]
# Überprüfe die Anzahl der Optionen
if len(split_options) < 2:
await interaction.response.send_message("Du musst mindestens 2 Optionen angeben.", ephemeral=True)
return
if len(split_options) > 20:
await interaction.response.send_message("Du kannst maximal 20 Optionen angeben.", ephemeral=True)
return
# Erstelle die Beschreibung für das Embed
description = []
for i, option in enumerate(split_options):
description.append(f"{self.poll_emojis[i]} {option}")
embed = discord.Embed(
title=f"📊 Umfrage: {question}",
description="\n".join(description),
color=discord.Color.dark_purple()
)
embed.set_footer(text=f"Umfrage gestartet von {interaction.user.display_name}")
# Sende die Nachricht und speichere sie, um Reaktionen hinzuzufügen
await interaction.response.send_message(embed=embed)
poll_message = await interaction.original_response()
# Füge die Reaktionen hinzu
for i in range(len(split_options)):
await poll_message.add_reaction(self.poll_emojis[i])
async def setup(bot: commands.Bot):
await bot.add_cog(Polls(bot))