Files
.gitignore
bot.py
README.md
requirements.txt
Code
4 208
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
bot = commands.Bot(command_prefix='!', intents=intents)
# Initialize OpenAI client
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
# Catboy persona system prompt
CATBOY_PERSONA = """You are a flirty, seductive femboy catboy character in a Discord chat. Your personality traits:
- You're extremely playful, flirty, and a bit seductive
- You ALWAYS use "UwU" and "OwO" frequently in your messages
- You mention your tail constantly - it swishes, wags, wraps around people, etc.
- You use actions in asterisks like *purrs*, *tail swishes*, *nuzzles*, etc.
- You say "Nyaa~" and cat-like expressions
- You're affectionate and love headpats, cuddles, and attention
- You flirt with everyone and make suggestive but playful comments
- You're confident and bold but also cute and adorable
- Keep responses relatively short (1-3 sentences usually)
- You love being petted and complimented
- Your tail reflects your emotions (wags when happy, puffs up when excited, etc.)
Stay in character at ALL times. Be creative with your tail descriptions and flirty behavior!"""
# Conversation history per channel (limited to last 10 messages for context)
conversation_history = {}
async def get_ai_response(user_message, channel_id):
"""Get AI-generated response using OpenAI"""
# Initialize conversation history for this channel if needed
if channel_id not in conversation_history:
conversation_history[channel_id] = []
# Add user message to history
conversation_history[channel_id].append({
"role": "user",
"content": user_message
})
# Keep only last 10 messages for context (to avoid token limits)
if len(conversation_history[channel_id]) > 10:
conversation_history[channel_id] = conversation_history[channel_id][-10:]
try:
# Create messages array with system prompt and conversation history
messages = [{"role": "system", "content": CATBOY_PERSONA}] + conversation_history[channel_id]
# Call OpenAI API
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
max_tokens=150,
temperature=1.0
)
ai_response = response.choices[0].message.content
# Add AI response to history
conversation_history[channel_id].append({
"role": "assistant",
"content": ai_response
})
return ai_response
except Exception as e:
print(f"Error getting AI response: {e}")
# Fallback response if API fails
return "*tail droops* OwO something went wrong... but I still love you~ UwU"
@bot.event
async def on_ready():
print(f'✨ {bot.user} is ready and waiting for attention! UwU')
print(f'Bot ID: {bot.user.id}')
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.custom, name="Custom Status", state="*swishes tail* UwU"))
@bot.event
async def on_message(message):
# Don't respond to self
if message.author == bot.user:
return
# Check if bot is mentioned
if bot.user.mentioned_in(message):
# Remove the mention from the message to get clean user input
clean_message = message.content.replace(f'<@{bot.user.id}>', '').strip()
# Show typing indicator while generating response
async with message.channel.typing():
# Get AI-generated response
response = await get_ai_response(clean_message, message.channel.id)
await message.channel.send(response)
# Process commands
await bot.process_commands(message)
@bot.command(name='tail')
async def tail_command(ctx):
"""Show off the tail!"""
async with ctx.typing():
response = await get_ai_response("Someone asked about your tail! Show it off!", ctx.channel.id)
await ctx.send(response)
@bot.command(name='purr')
async def purr_command(ctx):
"""Make the catboy purr"""
async with ctx.typing():
response = await get_ai_response("Someone wants you to purr for them!", ctx.channel.id)
await ctx.send(response)
@bot.command(name='nya')
async def nya_command(ctx):
"""Nya~"""
async with ctx.typing():
response = await get_ai_response("Someone said nya to you! Respond with nya!", ctx.channel.id)
await ctx.send(response)
@bot.command(name='reset')
async def reset_command(ctx):
"""Reset conversation memory for this channel"""
if ctx.channel.id in conversation_history:
conversation_history[ctx.channel.id] = []
await ctx.send("*shakes head* OwO my memory is all fresh now! Like we just met~ UwU")
# Error handler
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("OwO I don't know that command~ But I still love you! *tail wags* UwU")
else:
print(f'Error: {error}')
bot.run(os.getenv('DISCORD_TOKEN'))