+ Upload
This commit is contained in:
54
cogs/announcement.py
Normal file
54
cogs/announcement.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
|
||||
class Announcement(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@app_commands.command(name="announce", description="Sendet eine formatierte Ankündigung in einen Kanal.")
|
||||
@app_commands.describe(
|
||||
channel="Der Kanal, in den die Ankündigung gesendet werden soll.",
|
||||
title="Der Titel der Ankündigung.",
|
||||
message="Die Nachricht. Benutze '\\n' für Zeilenumbrüche.",
|
||||
color="Die Farbe des Embeds als HEX-Code (z.B. #FF5733).",
|
||||
mention="Eine Rolle, die mit der Ankündigung erwähnt werden soll."
|
||||
)
|
||||
@app_commands.checks.has_permissions(manage_messages=True)
|
||||
async def announce(self, interaction: discord.Interaction, channel: discord.TextChannel, title: str, message: str, color: str = None, mention: discord.Role = None):
|
||||
"""Erstellt und sendet eine Ankündigung."""
|
||||
|
||||
# Ersetze \n durch echte Zeilenumbrüche
|
||||
message = message.replace("\\n", "\n")
|
||||
|
||||
# Verarbeite die Farbe
|
||||
embed_color = discord.Color.blue() # Standardfarbe
|
||||
if color:
|
||||
try:
|
||||
# Entferne '#' und konvertiere HEX zu Integer
|
||||
embed_color = discord.Color(int(color.lstrip('#'), 16))
|
||||
except ValueError:
|
||||
await interaction.response.send_message("Ungültiger HEX-Farbcode. Bitte benutze ein Format wie `#FF5733`.", ephemeral=True)
|
||||
return
|
||||
|
||||
embed = discord.Embed(
|
||||
title=title,
|
||||
description=message,
|
||||
color=embed_color
|
||||
)
|
||||
embed.set_footer(text=f"Ankündigung von {interaction.user.display_name}")
|
||||
|
||||
# Erstelle den Inhalt der Nachricht (für den Ping)
|
||||
content = mention.mention if mention else None
|
||||
|
||||
try:
|
||||
await channel.send(content=content, embed=embed)
|
||||
await interaction.response.send_message(f"✅ Ankündigung wurde erfolgreich in {channel.mention} gesendet.", ephemeral=True)
|
||||
except discord.Forbidden:
|
||||
await interaction.response.send_message("❌ Ich habe keine Berechtigung, in diesem Kanal zu schreiben.", ephemeral=True)
|
||||
except Exception as e:
|
||||
await interaction.response.send_message(f"Ein Fehler ist aufgetreten: {e}", ephemeral=True)
|
||||
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(Announcement(bot))
|
Reference in New Issue
Block a user