From 6b9f25d052066f766e896d6cdecf72b622e9ff30 Mon Sep 17 00:00:00 2001 From: Marco Kohn Date: Sun, 6 Apr 2025 21:17:10 +0200 Subject: [PATCH] code for part3 --- main.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 563bd3a..d14f406 100644 --- a/main.py +++ b/main.py @@ -1,29 +1,33 @@ import os import discord +from discord.commands import Option from dotenv import load_dotenv intents = discord.Intents.default() intents.message_content = True # NOQA -bot = discord.Bot(intents=intents) +bot = discord.Bot(intents=intents, debug_guilds=[889424923859230720]) @bot.event async def on_ready(): print(f"{bot.user} ist online") -@bot.event -async def on_message(msg): - if msg.author.bot: - return - - await msg.channel.send("Du stinkst") +@bot.slash_command(description="Grüße einen User") +async def greet(ctx, user: Option(discord.User, "Der User, den du grüßen möchtest")): + await ctx.respond(f"Hallo {user.mention}") -@bot.event -async def on_message_delete(msg): - await msg.channel.send(f"Eine Nachricht von {msg.author} wurde gelöscht: {msg.content}") +@bot.slash_command(description="Lass den Bot eine Nachricht senden") +async def say( + ctx, + text: Option(str, "Der Text, den du senden möchtest"), + channel: Option(discord.TextChannel, "Der Channel, in den du die Nachricht senden möchtest") +): + await channel.send(text) + await ctx.respond("Nachricht gesendet", ephemeral=True) + load_dotenv() bot.run(os.getenv("DISCORD_TOKEN")) -- 2.47.2