New Bot thing
This commit is contained in:
44
main.py
Normal file
44
main.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user