main.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. load_dotenv()
  11. token = os.getenv("TOKEN")
  12. if token is None:
  13. raise ValueError("TOKEN not found in .env file")
  14. debug_guilds_up = []
  15. server_token = os.getenv("SERVER").split(",")
  16. for i in range(len(server_token)):
  17. debug_guilds_up.append(int(server_token[i]))
  18. bot = commands.Bot(
  19. command_prefix=commands.when_mentioned_or("!"),
  20. description="BaumSplitter41 Test Bot",
  21. intents=intents,
  22. debug_guilds=debug_guilds_up if debug_guilds_up else None
  23. )
  24. async def load_extensions():
  25. for filename in os.listdir("cogs"):
  26. if filename.endswith(".py"):
  27. await bot.load_extension(f"cogs.{filename[:-3]}")
  28. class Admin(commands.Cog):
  29. def __init__(self, bot):
  30. self.bot = bot
  31. @bot.event
  32. async def on_ready():
  33. print(f"{bot.user} ist online")
  34. @bot.listen()
  35. async def on_guild_join(guild):
  36. print(f"LOG: guild {guild} joined")
  37. #---------------------------------------------------------------------------------------#
  38. #DONT Touch anything above this line, unless you know what you are doing!#
  39. #---------------------------------------------------------------------------------------#
  40. #---------------------------------#
  41. ## Deleted Message
  42. """
  43. @bot.event
  44. async def on_message_delete(
  45. ctx = discord.Message,
  46. ):
  47. if ctx.author != bot.user:
  48. await ctx.send(f"Eine Nachricht von {ctx.author} wurde gelöscht: {ctx.content}", ephemeral=False)
  49. """
  50. #---------------------------------#
  51. #---------------------------------#
  52. @bot.event
  53. async def on_message_delete(msg):
  54. if msg.author != bot.user:
  55. await msg.channel.send(f"A Message from {msg.author} has been deleted: {msg.content}")
  56. #---------------------------------#
  57. #---------------------------------#
  58. ## Greet
  59. @bot.slash_command(description="Greet a User")
  60. async def greet(ctx, user: str = Option(discord.User, "The user, you want to greet")):
  61. await ctx.respond(f"Hello {user.mention}")
  62. #---------------------------------#
  63. #---------------------------------#
  64. ## Say
  65. @bot.slash_command(description="Let the bot send a message")
  66. async def say(
  67. ctx,
  68. text: str = Option(description="Input the text you want to send"),
  69. channel_input: discord.TextChannel = Option(description="Select the channel,where you want to send the message.")
  70. ):
  71. channel= discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
  72. await channel.send(text)
  73. await ctx.respond("Message sent", ephemeral=True)
  74. #---------------------------------#
  75. #---------------------------------#
  76. ## Userinfo
  77. @bot.slash_command(name="userinfo", description="Show informations of a user from this server")
  78. async def info(
  79. ctx,
  80. user: str = Option(discord.User, "Select User"),
  81. ):
  82. if user is None:
  83. user = ctx.author
  84. elif user not in ctx.guild.members:
  85. await ctx.respond("The selected user is not a member on this Server!", ephemeral=True)
  86. return
  87. elif user == bot.user:
  88. await ctx.respond(f"This is me - the {bot.user}", ephemeral=True)
  89. return
  90. embed = discord.Embed(
  91. title=f"Information about {user.name}",
  92. description=f"Here you see all details about {user.mention}",
  93. color=discord.Color.blue()
  94. )
  95. time = discord.utils.format_dt(user.created_at, "R")
  96. embed.add_field(name="Account creation date", value=time, inline=False)
  97. if len(user.roles) >= 2:
  98. embed.add_field(name="Roles", value=", ".join([role.mention for role in user.roles if role.name != "@everyone"]), inline=False)
  99. else:
  100. embed.add_field(name="Roles", value="User has no roles", inline=False)
  101. embed.add_field(name="Server join date", value=discord.utils.format_dt(user.joined_at, "R"), inline=False)
  102. embed.add_field(name="User ID", value=user.id)
  103. embed.set_thumbnail(url=user.display_avatar.url)
  104. embed.set_author(name="World Wide Modding - BaumSplitter41", icon_url="https://i.lcpdfrusercontent.com/uploads/monthly_2022_04/756701490_woldwidemodding.thumb.jpg.00bc1f61c05cc6d24519e1dda202d741.jpg")
  105. embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
  106. await ctx.respond(embed=embed)
  107. #---------------------------------#
  108. #---------------------------------#
  109. ## Serverinfo
  110. @bot.slash_command(name="serverinfo", description = "Show Informations to this Server")
  111. async def info(
  112. ctx,
  113. ):
  114. server = ctx.guild
  115. embed = discord.Embed(
  116. title=f"Serverinformations of {server.name}",
  117. description=f"Here you see all details about {server.name}",
  118. color=discord.Color.blue()
  119. )
  120. time = discord.utils.format_dt(server.created_at, "R")
  121. embed.add_field(name="Server creation date", value=time, inline=False)
  122. embed.add_field(name="Owner", value=server.owner, inline=False)
  123. embed.add_field(name="Member", value=server.member_count, inline=False)
  124. embed.add_field(name="Description", value=server.description, inline=False)
  125. embed.add_field(name="Server ID", value=server.id)
  126. embed.set_thumbnail(url=server.icon)
  127. embed.set_author(name="World Wide Modding - BaumSplitter41", icon_url="https://i.lcpdfrusercontent.com/uploads/monthly_2022_04/756701490_woldwidemodding.thumb.jpg.00bc1f61c05cc6d24519e1dda202d741.jpg")
  128. embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
  129. await ctx.respond(embed=embed)
  130. #---------------------------------#
  131. bot.run(token)