Forráskód Böngészése

Add files via upload

baumsplitter41 5 hónapja
szülő
commit
5cd75a7ebc
5 módosított fájl, 271 hozzáadás és 0 törlés
  1. 21 0
      VPD_BOT/bot_class.py
  2. 16 0
      VPD_BOT/cogs/base.py
  3. 206 0
      VPD_BOT/main.py
  4. 2 0
      gitignore.txt
  5. 26 0
      requirements.txt

+ 21 - 0
VPD_BOT/bot_class.py

@@ -0,0 +1,21 @@
+import os
+import discord
+import ezcord
+from dotenv import load_dotenv
+
+
+class Bot(ezcord.Bot):
+    def __init__(self):
+        intents = discord.Intents.default()
+        super().__init__(intents=intents)
+
+        self.load_cogs()
+
+    async def on_ready(self):
+        print(f"{self.name} ist online")
+
+
+if __name__ == "__main__":
+    load_dotenv()
+    bot = Bot()
+    bot.run(os.getenv("TOKEN"))

+ 16 - 0
VPD_BOT/cogs/base.py

@@ -0,0 +1,16 @@
+import discord
+from discord.ext import commands
+from discord.commands import slash_command
+
+
+class Base(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+
+    @slash_command(description="hello")
+    async def hello(self, ctx: discord.ApplicationContext):
+        await ctx.respond(f"Hey {ctx.author.mention}")
+
+
+def setup(bot: discord.Bot):
+    bot.add_cog(Base(bot))

+ 206 - 0
VPD_BOT/main.py

@@ -0,0 +1,206 @@
+import os
+from dotenv import load_dotenv
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+from datetime import datetime
+
+intents = discord.Intents.default()
+intents.message_content = True
+
+client = discord.Client(intents=intents)
+
+load_dotenv()
+token = os.getenv("TOKEN")
+if token is None:
+    raise ValueError("TOKEN not found in .env file")
+
+debug_guilds_up = []
+server_token = os.getenv("SERVER").split(",")
+for i in range(len(server_token)):
+    debug_guilds_up.append(int(server_token[i]))
+    
+bot = commands.Bot(
+    command_prefix=commands.when_mentioned_or("!"),
+    description="BaumSplitter41 Test Bot",
+    intents=intents,
+    debug_guilds=debug_guilds_up if debug_guilds_up else None
+)
+
+async def load_extensions():
+    for filename in os.listdir("cogs"):
+        if filename.endswith(".py"):
+            await bot.load_extension(f"cogs.{filename[:-3]}")   
+
+
+
+class Admin(commands.Cog):
+    def __init__(self, bot):
+        self.bot = bot
+
+@bot.event
+async def on_ready():
+    print(f"{bot.user} ist online")
+
+@bot.listen()
+async def on_guild_join(guild):
+    print(f"LOG: guild {guild} joined")
+
+
+#---------------------------------------------------------------------------------------#
+#DONT Touch anything above this line, unless you know what you are doing!#
+#---------------------------------------------------------------------------------------#
+
+#---------------------------------#
+## Deleted Message
+"""
+@bot.event
+async def on_message_delete(
+    ctx = discord.Message,
+):
+    if ctx.author != bot.user:
+        await ctx.send(f"Eine Nachricht von {ctx.author} wurde gelöscht: {ctx.content}", ephemeral=False)
+"""
+#---------------------------------#
+
+#---------------------------------#
+@bot.event
+async def on_message_delete(msg):
+    if msg.author != bot.user:  
+        await msg.channel.send(f"A Message from {msg.author} has been deleted: {msg.content}")
+#---------------------------------#
+
+#---------------------------------#
+## Greet
+@bot.slash_command(description="Greet a User")
+async def greet(ctx, user: str = Option(discord.User, "The user, you want to greet")):
+    await ctx.respond(f"Hello {user.mention}")
+#---------------------------------#
+
+#---------------------------------#
+## Say
+@bot.slash_command(description="Let the bot send a message")
+async def say(
+        ctx,
+        text: str = Option(description="Input the text you want to send"),
+        channel_input: discord.TextChannel = Option(description="Select the channel,where you want to send the message.")
+):  
+    channel= discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
+    await channel.send(text)
+    await ctx.respond("Message sent", ephemeral=True)
+#---------------------------------#
+
+#---------------------------------#
+## Userinfo
+@bot.slash_command(name="userinfo", description="Show informations of a user from this server")
+async def userinfo(
+        ctx,
+        user: str = Option(discord.User, "Select User"),
+    ):
+    if user is None:
+        user = ctx.author
+    elif user not in ctx.guild.members:
+        await ctx.respond("The selected user is not a member on this Server!", ephemeral=True)
+        return
+    elif user == bot.user:
+        await ctx.respond(f"This is me - the {bot.user}", ephemeral=True)
+        return
+
+
+    
+
+    embed = discord.Embed(
+        title=f"Information about *{user.name}*",
+        description=f"Here you see all details about {user.mention}",
+        color=discord.Color.blue()
+    )
+
+    time = discord.utils.format_dt(user.created_at, "R")
+
+    embed.add_field(name="Account creation date", value=time, inline=False)
+    if len(user.roles) >= 2:
+        embed.add_field(name="Roles", value=", ".join([role.mention for role in user.roles if role.name != "@everyone"]), inline=False)
+    else:
+        embed.add_field(name="Roles", value="User has no roles", inline=False)
+    embed.add_field(name="Server join date", value=discord.utils.format_dt(user.joined_at, "R"), inline=False)
+    embed.add_field(name="User ID", value=user.id)
+
+    embed.set_thumbnail(url=user.display_avatar.url)
+    embed.set_author(name="World Wide Modding", icon_url="https://i.lcpdfrusercontent.com/uploads/monthly_2022_04/756701490_woldwidemodding.thumb.jpg.00bc1f61c05cc6d24519e1dda202d741.jpg")
+    embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
+
+    await ctx.respond(embed=embed)
+#---------------------------------#
+
+
+#---------------------------------#
+##Ban System
+
+@bot.slash_command(name="ban", description="Ban a user from this Server")
+async def ban(
+    ctx,
+    user: Option(discord.User, description = "Select User", required=True), # type: ignore
+    reason: Option(str, description = "Reason for the ban", default="No reason provided") # type: ignore
+    
+):
+    if not ctx.author.guild_permissions.ban_members:
+        await ctx.respond("Error: You don't have the permission to ban Members!", ephemeral=True)
+        return
+    
+    if user == bot.user:
+        await ctx.respond("Error: I can't ban myself!", ephemeral=True)
+        return
+    if user == ctx.author:
+        await ctx.respond("Error: You can't ban yourself!", ephemeral=True)
+        return
+    
+    #logging in #ban-logs on VicePD
+    channel= discord.utils.get(ctx.guild.channels, id = int(1447580463668400305))
+
+    embed = discord.Embed(
+        title=f"Ban of **{user.name}**",
+        description=f"User {user.mention} has been banned from the Server",
+        color=discord.Color.red()
+    )
+    time = discord.utils.format_dt(datetime.now(), "f")
+    embed.add_field(name="Ban Date", value=time, inline=False)
+    embed.add_field(name="Moderator", value=f"{ctx.author}", inline=False)
+    embed.add_field(name="Reason", value=reason, inline=False)
+
+    embed.add_field(name="User ID", value=user.id)
+
+    embed.set_thumbnail(url=user.display_avatar.url)
+    embed.set_footer(text="World Wide Modding - Bot | Made by BaumSplitter41")
+
+    try:
+        await ctx.guild.ban(user, reason=reason)
+        await ctx.respond(f"User {user.mention} has been banned from this Server!", ephemeral=True)
+        await channel.send(embed=embed)
+
+    except discord.Forbidden:
+        await ctx.respond("Error: I don't have permission to ban this user.", ephemeral=True)
+    except discord.HTTPException as e:
+        await ctx.respond(f"Error: Could not ban User {user.mention}. Reason: {e}", ephemeral=True)
+    except Exception as e:
+        await ctx.respond(f"Unexpected error: {e}", ephemeral=True)
+
+#---------------------------------#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#---------------------------------#
+#Run function
+bot.run(token)
+#---------------------------------#

+ 2 - 0
gitignore.txt

@@ -0,0 +1,2 @@
+*/.env
+VPD_BOT/example.env

+ 26 - 0
requirements.txt

@@ -0,0 +1,26 @@
+aiocache==0.12.3
+aiohappyeyeballs==2.6.1
+aiohttp==3.13.2
+aiosignal==1.4.0
+aiosqlite==0.21.0
+attrs==25.4.0
+audioop-lts==0.2.2
+cffi==2.0.0
+colorama==0.4.6
+dotenv==0.9.9
+ezcord==0.7.2
+ffmpeg-python==0.2.0
+frozenlist==1.8.0
+future==1.0.0
+idna==3.11
+imageio-ffmpeg==0.6.0
+multidict==6.7.0
+numpy==2.3.5
+propcache==0.4.1
+py-cord==2.6.1
+pycparser==2.23
+PyNaCl==1.5.0
+python-dotenv==1.2.1
+PyYAML==6.0.3
+typing_extensions==4.15.0
+yarl==1.22.0