feat(bot): add initial bot setup and commands 🎉

- Created a Dockerfile for containerization.
- Added .env.example for environment variable configuration.
- Implemented main bot functionality with meme command and webhook integration.

*Generated by Github Copilot*
This commit is contained in:
2025-10-13 18:53:23 +02:00
parent 6a7d1f13ea
commit c85e1c909c
4 changed files with 76 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
DISCORD_TOKEN=
WEBHOOK_URL=
API_KEY=
+10
View File
@@ -0,0 +1,10 @@
FROM python:3.12-slim
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r src/requirements.txt
# Run the bot
CMD ["python", "src/main.py"]
+61
View File
@@ -0,0 +1,61 @@
import os
import discord
import httpx
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)
@client.event
async def on_ready():
print(f"Bot logged in as {client.user}")
try:
await tree.sync()
print("Slash commands synced successfully.")
except Exception as e:
print(f"Failed to sync commands: {e}")
@tree.command(name="meme", description="Create a meme based on your prompt")
async def meme(interaction: discord.Interaction, prompt: str):
# Defer the response immediately to avoid timeout
await interaction.response.defer()
try:
# Call the webhook with the prompt and API key
webhook_payload = {"query": prompt}
headers = {"apiKey": os.getenv("API_KEY"), "Content-Type": "application/json"}
async with httpx.AsyncClient() as httpx_client:
response = await httpx_client.post(
os.getenv("WEBHOOK_URL"),
json=webhook_payload,
headers=headers,
timeout=120,
)
if response.status_code == 200:
image_url = response.json()["data"]["url"]
embed = discord.Embed(
title="New meme just dropped!", description=prompt, color=0x00FF00
)
embed.set_image(url=image_url)
await interaction.followup.send(embed=embed)
else:
embed = discord.Embed(
title=f"Webhook call failed - {response.status_code}",
description=response.text,
color=0xFF0000,
)
await interaction.followup.send(embed=embed)
except Exception as e:
embed = discord.Embed(
title="Exception",
description=str(e),
color=0xFF0000,
)
client.run(os.getenv("DISCORD_TOKEN"))
+2
View File
@@ -0,0 +1,2 @@
discord.py==2.6.3
httpx==0.28.1