main.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. from datetime import datetime
  8. intents = discord.Intents.default()
  9. intents.message_content = True
  10. client = discord.Client(intents=intents)
  11. load_dotenv()
  12. token = os.getenv("TOKEN")
  13. if token is None:
  14. raise ValueError("TOKEN not found in .env file")
  15. debug_guilds_up = []
  16. server_token = os.getenv("SERVER").split(",")
  17. for i in range(len(server_token)):
  18. debug_guilds_up.append(int(server_token[i]))
  19. bot = commands.Bot(
  20. command_prefix=commands.when_mentioned_or("!"),
  21. description="BaumSplitter41 Test Bot",
  22. intents=intents,
  23. debug_guilds=debug_guilds_up if debug_guilds_up else None
  24. )
  25. async def load_extensions():
  26. for filename in os.listdir("cogs"):
  27. if filename.endswith(".py"):
  28. await bot.load_extension(f"cogs.{filename[:-3]}")
  29. class Admin(commands.Cog):
  30. def __init__(self, bot):
  31. self.bot = bot
  32. @bot.event
  33. async def on_ready():
  34. print(f"{bot.user} ist online")
  35. @bot.listen()
  36. async def on_guild_join(guild):
  37. print(f"LOG: guild {guild} joined")
  38. #---------------------------------------------------------------------------------------#
  39. #DONT Touch anything above this line, unless you know what you are doing!#
  40. #---------------------------------------------------------------------------------------#
  41. #---------------------------------#
  42. ## Deleted Message
  43. """
  44. @bot.event
  45. async def on_message_delete(
  46. ctx = discord.Message,
  47. ):
  48. if ctx.author != bot.user:
  49. await ctx.send(f"Eine Nachricht von {ctx.author} wurde gelöscht: {ctx.content}", ephemeral=False)
  50. """
  51. #---------------------------------#
  52. #---------------------------------#
  53. @bot.event
  54. async def on_message_delete(msg):
  55. if msg.author != bot.user:
  56. await msg.channel.send(f"A Message from {msg.author} has been deleted: {msg.content}")
  57. #---------------------------------#
  58. #---------------------------------#
  59. ## Greet
  60. @bot.slash_command(description="Greet a User")
  61. async def greet(ctx, user: str = Option(discord.User, "The user, you want to greet")):
  62. await ctx.respond(f"Hello {user.mention}")
  63. #---------------------------------#
  64. #---------------------------------#
  65. ## Say
  66. @bot.slash_command(description="Let the bot send a message")
  67. async def say(
  68. ctx,
  69. text: str = Option(description="Input the text you want to send"),
  70. channel_input: discord.TextChannel = Option(description="Select the channel,where you want to send the message.")
  71. ):
  72. channel= discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
  73. await channel.send(text)
  74. await ctx.respond("Message sent", ephemeral=True)
  75. #---------------------------------#
  76. #---------------------------------#
  77. ## Userinfo
  78. @bot.slash_command(name="userinfo", description="Show informations of a user from this server")
  79. async def userinfo(
  80. ctx,
  81. user: str = Option(discord.User, "Select User"),
  82. ):
  83. if user is None:
  84. user = ctx.author
  85. elif user not in ctx.guild.members:
  86. await ctx.respond("The selected user is not a member on this Server!", ephemeral=True)
  87. return
  88. elif user == bot.user:
  89. await ctx.respond(f"This is me - the {bot.user}", ephemeral=True)
  90. return
  91. embed = discord.Embed(
  92. title=f"Information about *{user.name}*",
  93. description=f"Here you see all details about {user.mention}",
  94. color=discord.Color.blue()
  95. )
  96. time = discord.utils.format_dt(user.created_at, "R")
  97. embed.add_field(name="Account creation date", value=time, inline=False)
  98. if len(user.roles) >= 2:
  99. embed.add_field(name="Roles", value=", ".join([role.mention for role in user.roles if role.name != "@everyone"]), inline=False)
  100. else:
  101. embed.add_field(name="Roles", value="User has no roles", inline=False)
  102. embed.add_field(name="Server join date", value=discord.utils.format_dt(user.joined_at, "R"), inline=False)
  103. embed.add_field(name="User ID", value=user.id)
  104. embed.set_thumbnail(url=user.display_avatar.url)
  105. embed.set_author(name="World Wide Modding", icon_url="https://i.lcpdfrusercontent.com/uploads/monthly_2022_04/756701490_woldwidemodding.thumb.jpg.00bc1f61c05cc6d24519e1dda202d741.jpg")
  106. embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
  107. await ctx.respond(embed=embed)
  108. #---------------------------------#
  109. #---------------------------------#
  110. ## Serverinfo
  111. @bot.slash_command(name="serverinfo", description = "Show Informations to this Server")
  112. async def serverinfo(
  113. ctx,
  114. ):
  115. server = ctx.guild
  116. owner = server.owner_id
  117. owner = await bot.fetch_user(owner)
  118. print(owner)
  119. embed = discord.Embed(
  120. title=f"Information about the server __{server.name}__",
  121. description=f"Here you see all details about {server.name}",
  122. color=discord.Color.blue()
  123. )
  124. time = discord.utils.format_dt(server.created_at, "R")
  125. embed.add_field(name="Server creation date", value=time, inline=False)
  126. embed.add_field(name="Owner", value=owner.mention, inline=False)
  127. embed.add_field(name="Member", value=server.member_count, inline=False)
  128. embed.add_field(name="Description", value=server.description, inline=False)
  129. embed.add_field(name="Server ID", value=server.id)
  130. embed.set_thumbnail(url=server.icon)
  131. embed.set_author(name="World Wide Modding", icon_url="https://i.lcpdfrusercontent.com/uploads/monthly_2022_04/756701490_woldwidemodding.thumb.jpg.00bc1f61c05cc6d24519e1dda202d741.jpg")
  132. embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
  133. await ctx.respond(embed=embed)
  134. #---------------------------------#
  135. ##Ban System
  136. @bot.slash_command(name="ban", description="Ban a user from this Server")
  137. async def ban(
  138. ctx,
  139. user: Option(discord.User, description = "Select User", required=True), # type: ignore
  140. reason: Option(str, description = "Reason for the ban", default="No reason provided") # type: ignore
  141. ):
  142. if not ctx.author.guild_permissions.ban_members:
  143. await ctx.respond("Error: You don't have the permission to ban Members!", ephemeral=True)
  144. return
  145. if user == bot.user:
  146. await ctx.respond("Error: I can't ban myself!", ephemeral=True)
  147. return
  148. if user == ctx.author:
  149. await ctx.respond("Error: You can't ban yourself!", ephemeral=True)
  150. return
  151. #logging in #ban-logs on VicePD
  152. channel= discord.utils.get(ctx.guild.channels, id = int(1447580463668400305))
  153. embed = discord.Embed(
  154. title=f"Ban of **{user.name}**",
  155. description=f"User {user.mention} has been banned from the Server",
  156. color=discord.Color.red()
  157. )
  158. time = discord.utils.format_dt(datetime.now(), "f")
  159. embed.add_field(name="Ban Date", value=time, inline=False)
  160. embed.add_field(name="Moderator", value=f"{ctx.author}", inline=False)
  161. embed.add_field(name="Reason", value=reason, inline=False)
  162. embed.add_field(name="User ID", value=user.id)
  163. embed.set_thumbnail(url=user.display_avatar.url)
  164. embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
  165. try:
  166. await ctx.guild.ban(user, reason=reason)
  167. await ctx.respond(f"User {user.mention} has been banned from this Server!", ephemeral=True)
  168. await channel.send(embed=embed)
  169. except discord.Forbidden:
  170. await ctx.respond("Error: I don't have permission to ban this user.", ephemeral=True)
  171. except discord.HTTPException as e:
  172. await ctx.respond(f"Error: Could not ban User {user.mention}. Reason: {e}", ephemeral=True)
  173. except Exception as e:
  174. await ctx.respond(f"Unexpected error: {e}", ephemeral=True)
  175. bot.run(token)