Parcourir la source

Add files via upload

baumsplitter41 il y a 5 mois
Parent
commit
fd53b63894
4 fichiers modifiés avec 247 ajouts et 0 suppressions
  1. 21 0
      TEST_BOT_BAUM/bot_class.py
  2. 16 0
      TEST_BOT_BAUM/cogs/base.py
  3. 117 0
      TEST_BOT_BAUM/main.py
  4. 93 0
      TEST_BOT_BAUM/main_2py.py

+ 21 - 0
TEST_BOT_BAUM/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.user} ist online")
+
+
+if __name__ == "__main__":
+    load_dotenv()
+    bot = Bot()
+    bot.run(os.getenv("TOKEN"))

+ 16 - 0
TEST_BOT_BAUM/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))

+ 117 - 0
TEST_BOT_BAUM/main.py

@@ -0,0 +1,117 @@
+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
+
+intents = discord.Intents.default()
+intents.message_content = True
+
+client = discord.Client(intents=intents)
+
+bot = commands.Bot(
+    command_prefix=commands.when_mentioned_or("!"),
+    description="BaumSplitter41 Test Bot",
+    intents=intents,
+    #debug_guilds=[1423227652386455665],
+    debug_guilds=[962718321655025684, 1423227652386455665]    # hier server id einfügen
+)
+
+async def load_extensions():
+    for filename in os.listdir("cogs"):
+        if filename.endswith(".py"):
+            await bot.load_extension(f"cogs.{filename[:-3]}")   
+
+load_dotenv()
+token = os.getenv("TOKEN")
+if token is None:
+    raise ValueError("TOKEN not found in .env file")
+
+
+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!#
+#---------------------------------------------------------------------------------------#
+
+
+@bot.event
+async def on_message_delete(msg):
+    if msg.author != bot.user:
+        await msg.channel.send(f"Eine Nachricht von {msg.author} wurde gelöscht: {msg.content}")
+
+
+
+
+@bot.slash_command(description="Grüße einen User")
+async def greet(ctx, user: str = Option(discord.User, "Der User, den du grüßen möchtest")):
+    await ctx.respond(f"Hallo {user.mention}")
+
+
+@bot.slash_command(description="Lass den Bot eine Nachricht senden")
+async def say(
+        ctx,
+        text: str = Option(description="Der Text, den du senden möchtest"),
+        channel: discord.TextChannel = Option(description="Der Channel, in den du die Nachricht senden möchtest")
+):
+    await channel.send(text)
+    await ctx.respond("Nachricht gesendet", ephemeral=True)
+
+
+@bot.slash_command(name="userinfo", description="Zeige Infos über einen User")
+async def info(
+        ctx,
+        user: discord.Member = Option(description="Gib einen User an", default=None),
+    ):
+    if user is None:
+        user = ctx.author
+
+    embed = discord.Embed(
+        title=f"Infos über {user.name}",
+        description=f"Hier siehst du alle Details über {user.mention}",
+        color=discord.Color.blue()
+    )
+
+    time = discord.utils.format_dt(user.created_at, "R")
+
+    embed.add_field(name="Account erstellt", value=time, inline=False)
+    embed.add_field(name="ID", value=user.id)
+
+    embed.set_thumbnail(url=ctx.author.display_avatar.url)
+    embed.set_footer(text="World Wide Modding - Bot")
+
+    await ctx.respond(embed=embed)
+
+
+@slash_command()
+@commands.has_permissions(administrator=True)
+async def hallo(self, ctx):
+    await ctx.respond("Hey")
+
+@commands.Cog.listener()
+async def on_application_command_error(self, ctx, error):
+    if isinstance(error, commands.CheckFailure):
+        await ctx.respond(f"Nur Admins dürfen diesen Befehl ausführen!", ephemeral=True)
+        return
+
+    await ctx.respond(f"Es ist ein Fehler aufgetreten: ```{error}```", ephemeral=True)
+    raise error
+
+
+
+
+
+
+bot.run(token)

+ 93 - 0
TEST_BOT_BAUM/main_2py.py

@@ -0,0 +1,93 @@
+# This example requires the 'members' privileged intent to use the Member converter
+# and the 'message_content' privileged intent for prefixed commands.
+
+import random
+import os
+from dotenv import load_dotenv
+import discord
+from discord.ext import commands
+
+description = """
+An example bot to showcase the discord.ext.commands extension module.
+There are a number of utility commands being showcased here.
+"""
+load_dotenv()
+token = os.getenv("TOKEN")
+if token is None:
+    raise ValueError("TOKEN not found in .env file")
+
+intents = discord.Intents.default()
+intents.members = True
+intents.message_content = True
+
+bot = commands.Bot(
+    command_prefix=commands.when_mentioned_or("!"),
+    description=description,
+    intents=intents,
+)
+
+
+@bot.event
+async def on_ready():
+    print(f"Logged in as {bot.user} (ID: {bot.user.id})")
+    print("------")
+
+
+@bot.command()
+async def add(ctx: commands.Context, left: int, right: int):
+    """Adds two numbers together."""
+    await ctx.send(str(left + right))
+
+
+@bot.command()
+async def roll(ctx: commands.Context, dice: str):
+    """Rolls a die in NdN format."""
+    try:
+        rolls, limit = map(int, dice.split("d"))
+    except ValueError:
+        await ctx.send("Format has to be in NdN!")
+        return
+
+    # _ is used in the generation of our result as we don't need the number that comes from the usage of range(rolls).
+    result = ", ".join(str(random.randint(1, limit)) for _ in range(rolls))
+    await ctx.send(result)
+
+
+@bot.command(description="For when you wanna settle the score some other way")
+async def choose(ctx: commands.Context, *choices: str):
+    """Chooses between multiple choices."""
+    await ctx.send(random.choice(choices))
+
+
+@bot.command()
+async def repeat(ctx: commands.Context, times: int, *, content: str = "repeating..."):
+    """Repeats a message multiple times."""
+    for _ in range(times):
+        await ctx.send(content)
+
+
+@bot.command()
+async def joined(ctx: commands.Context, member: discord.Member):
+    """Says when a member joined."""
+    await ctx.send(f"{member.name} joined in {member.joined_at}")
+
+
+@bot.group()
+async def cool(ctx: commands.Context):
+    """
+    Says if a user is cool.
+
+    In reality this just checks if a subcommand is being invoked.
+    """
+
+    if ctx.invoked_subcommand is None:
+        await ctx.send(f"No, {ctx.subcommand_passed} is not cool")
+
+
+@cool.command(name="bot")
+async def _bot(ctx: commands.Context):
+    """Is the bot cool?"""
+    await ctx.send("Yes, the bot is cool.")
+
+
+bot.run(token)