-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
58 lines (43 loc) · 1.44 KB
/
bot.py
File metadata and controls
58 lines (43 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import random
import json
import discord
from discord.ext import commands
# --- Initialization and Setup ---
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)
# Load quotes globally
try:
with open('quotes.json', 'r') as f:
VOID_HUMOR_QUOTES = json.load(f)
print(f"Loaded {len(VOID_HUMOR_QUOTES)} quotes.")
except Exception as e:
print(f"ERROR loading quotes: {e}")
VOID_HUMOR_QUOTES = []
# --- Bot Events ---
@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}. Ready to whisper absurdities.")
# Sync global slash commands.
try:
await bot.tree.sync()
print("Slash commands sync initiated.")
except Exception as e:
print(f"Sync failed: {e}")
# --- Slash Command ---
@bot.tree.command(name="voidhumor", description="Get a random, absurd, dark humor quote.")
async def voidhumor(interaction: discord.Interaction):
"""Retrieves and sends a random quote."""
if VOID_HUMOR_QUOTES:
quote = random.choice(VOID_HUMOR_QUOTES)
message = f"**The Void Whispers:**\n>>> {quote}"
else:
message = "The void is silent. I couldn't find the quotes."
await interaction.response.send_message(message)
# --- Run Bot ---
# Retrieve the token set in Replit Secrets
BOT_TOKEN = os.getenv('DISCORD_BOT_TOKEN')
if BOT_TOKEN:
bot.run(BOT_TOKEN)
else:
print('FATAL ERROR: DISCORD_BOT_TOKEN not found.')