Skip to content

Commit

Permalink
Tickets Error Handling, Role Command Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Nov 14, 2024
1 parent aaebda0 commit 8758f26
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions cogs/tickets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nextcord
from nextcord.ext import commands
from nextcord.ui import Button, View
from nextcord.ext.commands import has_permissions
from nextcord.ext.commands import has_permissions, CommandInvokeError
import utils.constants as constants
import json
import os
Expand Down Expand Up @@ -130,16 +130,16 @@ async def update_ticket_message(self, ctx):

@tickets.command(name="role")
@has_permissions(manage_channels=True)
async def add_ticket_roles(self, ctx, *role_ids: int):
async def add_ticket_roles(self, ctx, *roles: nextcord.Role):
if 'ticket_roles' not in self.data:
self.data['ticket_roles'] = []

for role_id in role_ids:
if role_id not in self.data['ticket_roles']:
self.data['ticket_roles'].append(role_id)
for role in roles:
if role.id not in self.data['ticket_roles']:
self.data['ticket_roles'].append(role.id)

self.save_config()
role_mentions = " ".join([f"<@&{role_id}>" for role_id in role_ids])
role_mentions = " ".join([role.mention for role in roles])
await ctx.send(f"Roles {role_mentions} added to ticket access.")

@tickets.command(name="channel")
Expand Down Expand Up @@ -250,12 +250,17 @@ async def close_ticket(self, interaction: nextcord.Interaction, thread: nextcord
self.data['buttons'] = [button for button in self.data['buttons'] if button['message_id'] != thread.last_message_id]
self.save_config()

@tickets.error
@setup_ticket.error
@setup_log.error
async def tickets_error(self, ctx, error):
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You don't have permission to use this command.")
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Please provide the required arguments.")
elif isinstance(error, CommandInvokeError):
original = getattr(error, "original", error)
await ctx.send(f"An error occurred: {original}")
else:
await ctx.send(f"An error occurred: {error}")

def setup(bot):
bot.add_cog(TicketSystem(bot))

0 comments on commit 8758f26

Please sign in to comment.