From d28fd621092d53a7127bdf52d5d6cb07886d6913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Thu, 16 Nov 2023 21:52:22 +0100 Subject: [PATCH] New Bot thing --- main.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..a5e0fb5 --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +import discord +import os # default module +from dotenv import load_dotenv +import json + +load_dotenv() # load all the variables from the env file +bot = discord.Bot() + +@bot.event +async def on_ready(): + bot.add_view(CounterView()) + print(f"{bot.user} is ready and online!") + + +def create_embed(counter): + embed = discord.Embed( + title="Sparschwein", + color=discord.Colour.blurple(), + ) + embed.add_field(name="Aktueller Stand:", value=counter) + return embed + + +async def getmsg(ctx, msgID: int): # yes, you can do msg: discord.Message + msg = await ctx.fetch_message(msgID) # you now have the message object from the id + + +class CounterView(discord.ui.View): # Create a class called MyView that subclasses discord.ui.View + def __init__(self): + super().__init__(timeout=None) # timeout of the view must be set to None + + @discord.ui.button(label="+1", custom_id="count_plus_one",style=discord.ButtonStyle.primary) + async def button_callback(self, button, interaction): + await interaction.response.send_message("You clicked the button!") # Send a message when the button is clicked + + +@bot.slash_command(name = "set_channel", description = "Setze den Channel, in dem der Zähler erstellt wird.") +async def set_channel(ctx): + channel = ctx.channel + await channel.send(embed=create_embed(2), view=CounterView()) + await ctx.respond(content="Done", ephemeral=True) +#await ctx.respond(embed=create_embed(2)) + +bot.run(os.getenv('TOKEN')) # run the bot with the token