main.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import os
  2. from dotenv import load_dotenv
  3. import discord
  4. from discord.ext import commands
  5. from discord.commands import Option
  6. from discord.commands import slash_command
  7. intents = discord.Intents.default()
  8. intents.message_content = True
  9. client = discord.Client(intents=intents)
  10. bot = commands.Bot(
  11. command_prefix=commands.when_mentioned_or("!"),
  12. description="BaumSplitter41 Test Bot",
  13. intents=intents,
  14. #debug_guilds=[1423227652386455665],
  15. debug_guilds=[962718321655025684, 1423227652386455665] # hier server id einfügen
  16. )
  17. async def load_extensions():
  18. for filename in os.listdir("cogs"):
  19. if filename.endswith(".py"):
  20. await bot.load_extension(f"cogs.{filename[:-3]}")
  21. load_dotenv()
  22. token = os.getenv("TOKEN")
  23. if token is None:
  24. raise ValueError("TOKEN not found in .env file")
  25. class Admin(commands.Cog):
  26. def __init__(self, bot):
  27. self.bot = bot
  28. @bot.event
  29. async def on_ready():
  30. print(f"{bot.user} ist online")
  31. @bot.listen()
  32. async def on_guild_join(guild):
  33. print(f"LOG: guild {guild} joined")
  34. #---------------------------------------------------------------------------------------#
  35. #DONT Touch anything above this line, unless you know what you are doing!#
  36. #---------------------------------------------------------------------------------------#
  37. @bot.event
  38. async def on_message_delete(msg):
  39. if msg.author != bot.user:
  40. await msg.channel.send(f"Eine Nachricht von {msg.author} wurde gelöscht: {msg.content}")
  41. @bot.slash_command(description="Grüße einen User")
  42. async def greet(ctx, user: str = Option(discord.User, "Der User, den du grüßen möchtest")):
  43. await ctx.respond(f"Hallo {user.mention}")
  44. @bot.slash_command(description="Lass den Bot eine Nachricht senden")
  45. async def say(
  46. ctx,
  47. text: str = Option(description="Der Text, den du senden möchtest"),
  48. channel: discord.TextChannel = Option(description="Der Channel, in den du die Nachricht senden möchtest")
  49. ):
  50. await channel.send(text)
  51. await ctx.respond("Nachricht gesendet", ephemeral=True)
  52. @bot.slash_command(name="userinfo", description="Zeige Infos über einen User")
  53. async def info(
  54. ctx,
  55. user: discord.Member = Option(description="Gib einen User an", default=None),
  56. ):
  57. if user is None:
  58. user = ctx.author
  59. embed = discord.Embed(
  60. title=f"Infos über {user.name}",
  61. description=f"Hier siehst du alle Details über {user.mention}",
  62. color=discord.Color.blue()
  63. )
  64. time = discord.utils.format_dt(user.created_at, "R")
  65. embed.add_field(name="Account erstellt", value=time, inline=False)
  66. embed.add_field(name="ID", value=user.id)
  67. embed.set_thumbnail(url=ctx.author.display_avatar.url)
  68. embed.set_footer(text="World Wide Modding - Bot")
  69. await ctx.respond(embed=embed)
  70. @slash_command()
  71. @commands.has_permissions(administrator=True)
  72. async def hallo(self, ctx):
  73. await ctx.respond("Hey")
  74. @commands.Cog.listener()
  75. async def on_application_command_error(self, ctx, error):
  76. if isinstance(error, commands.CheckFailure):
  77. await ctx.respond(f"Nur Admins dürfen diesen Befehl ausführen!", ephemeral=True)
  78. return
  79. await ctx.respond(f"Es ist ein Fehler aufgetreten: ```{error}```", ephemeral=True)
  80. raise error
  81. bot.run(token)