Files
.gitignore
bot.py
requirements.txt
Code
3 213
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
import asyncio
load_dotenv()
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
TICKET_CATEGORY = "Tickets"
STAFF_ROLE_NAME = "Support Staff"
@bot.event
async def on_ready():
print(f'✅ FrostyTicket Bot is online!')
print(f'Logged in as {bot.user.name} ({bot.user.id})')
print('─' * 40)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Tickets | !ticket"))
def is_owner():
async def predicate(ctx):
return await bot.is_owner(ctx.author)
return commands.check(predicate)
def is_ticket_channel():
async def predicate(ctx):
return ctx.channel.name.startswith('ticket-')
return commands.check(predicate)
@bot.command(name='ticket')
async def create_ticket(ctx):
guild = ctx.guild
author = ctx.author
existing_ticket = discord.utils.get(guild.text_channels, name=f'ticket-{author.name.lower()}')
if existing_ticket:
await ctx.send(f'❌ You already have an open ticket: {existing_ticket.mention}')
return
category = discord.utils.get(guild.categories, name=TICKET_CATEGORY)
if not category:
category = await guild.create_category(TICKET_CATEGORY)
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
author: discord.PermissionOverwrite(read_messages=True, send_messages=True),
guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True)
}
staff_role = discord.utils.get(guild.roles, name=STAFF_ROLE_NAME)
if staff_role:
overwrites[staff_role] = discord.PermissionOverwrite(read_messages=True, send_messages=True)
ticket_channel = await guild.create_text_channel(
name=f'ticket-{author.name.lower()}',
category=category,
overwrites=overwrites
)
embed = discord.Embed(
title='🎫 Support Ticket',
description=f'Welcome {author.mention}!\n\nSupport staff will be with you shortly.\n\nPlease describe your issue in detail.',
color=discord.Color.blue()
)
embed.set_footer(text='FrostyTicket System')
await ticket_channel.send(embed=embed)
await ctx.send(f'✅ Ticket created: {ticket_channel.mention}')
@bot.command(name='close')
@is_owner()
@is_ticket_channel()
async def close_ticket(ctx, *, reason: str = 'No reason provided'):
embed = discord.Embed(
title='🔒 Ticket Closing',
description=f'This ticket will be closed in 5 seconds.\n\n**Reason:** {reason}',
color=discord.Color.red()
)
embed.set_footer(text=f'Closed by {ctx.author.name}')
await ctx.send(embed=embed)
await asyncio.sleep(5)
log_embed = discord.Embed(
title='📋 Ticket Closed',
description=f'**Channel:** {ctx.channel.name}\n**Closed by:** {ctx.author.mention}\n**Reason:** {reason}',
color=discord.Color.orange()
)
log_channel = discord.utils.get(ctx.guild.text_channels, name='ticket-logs')
if log_channel:
await log_channel.send(embed=log_embed)
await ctx.channel.delete()
@bot.command(name='ping')
@is_owner()
@is_ticket_channel()
async def ping_staff(ctx):
staff_role = discord.utils.get(ctx.guild.roles, name=STAFF_ROLE_NAME)
if staff_role:
embed = discord.Embed(
title='🔔 Staff Alert',
description=f'{staff_role.mention} - Attention needed in this ticket!',
color=discord.Color.gold()
)
embed.set_footer(text=f'Pinged by {ctx.author.name}')
await ctx.send(embed=embed)
else:
await ctx.send('❌ Staff role not found. Please create a role named "Support Staff".')
@bot.command(name='edit')
@is_owner()
@is_ticket_channel()
async def edit_ticket(ctx, field: str, *, value: str):
if field.lower() == 'topic':
await ctx.channel.edit(topic=value)
embed = discord.Embed(
title='✏️ Ticket Updated',
description=f'**Topic updated to:**\n{value}',
color=discord.Color.green()
)
embed.set_footer(text=f'Edited by {ctx.author.name}')
await ctx.send(embed=embed)
elif field.lower() == 'name':
await ctx.channel.edit(name=value)
embed = discord.Embed(
title='✏️ Ticket Updated',
description=f'**Channel name updated to:**\n{value}',
color=discord.Color.green()
)
embed.set_footer(text=f'Edited by {ctx.author.name}')
await ctx.send(embed=embed)
else:
await ctx.send('❌ Invalid field. Use `topic` or `name`.')
@bot.command(name='add')
@is_owner()
@is_ticket_channel()
async def add_user(ctx, member: discord.Member):
await ctx.channel.set_permissions(member, read_messages=True, send_messages=True)
embed = discord.Embed(
title='➕ User Added',
description=f'{member.mention} has been added to this ticket.',
color=discord.Color.green()
)
await ctx.send(embed=embed)
@bot.command(name='remove')
@is_owner()
@is_ticket_channel()
async def remove_user(ctx, member: discord.Member):
await ctx.channel.set_permissions(member, overwrite=None)
embed = discord.Embed(
title='➖ User Removed',
description=f'{member.mention} has been removed from this ticket.',
color=discord.Color.orange()
)
await ctx.send(embed=embed)
@bot.command(name='setup')
@is_owner()
async def setup_tickets(ctx):
guild = ctx.guild
category = discord.utils.get(guild.categories, name=TICKET_CATEGORY)
if not category:
category = await guild.create_category(TICKET_CATEGORY)
log_channel = discord.utils.get(guild.text_channels, name='ticket-logs')
if not log_channel:
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True)
}
log_channel = await guild.create_text_channel(name='ticket-logs', overwrites=overwrites)
embed = discord.Embed(
title='✅ FrostyTicket Setup Complete',
description=f'**Category:** {TICKET_CATEGORY}\n**Log Channel:** {log_channel.mention}\n\nUsers can now create tickets using `!ticket`',
color=discord.Color.blue()
)
await ctx.send(embed=embed)
@close_ticket.error
@ping_staff.error
@edit_ticket.error
@add_user.error
@remove_user.error
@setup_tickets.error
async def command_error(ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send('❌ You do not have permission to use this command. Owner only!')
else:
await ctx.send(f'❌ An error occurred: {str(error)}')