Skip to content

Instantly share code, notes, and snippets.

@zRitsu
Last active December 2, 2022 12:08
Show Gist options
  • Save zRitsu/8a80f9801dba743fcb7d243c5cbe4ca9 to your computer and use it in GitHub Desktop.
Save zRitsu/8a80f9801dba743fcb7d243c5cbe4ca9 to your computer and use it in GitHub Desktop.
sistema de ticket para disnake.
from typing import Optional
import disnake
from disnake.ext import commands
id_do_servidor = 123456789 # coloque o id do servidor aqui
id_do_cargo_mod = 1234567890 #coloque o id do cargo no lugar do número ao lado (para ser marcado quando abrirem novos tickets)
class TicketSystem(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.ticket_channel_ids = set()
@commands.slash_command(
description="Definir um canal para criar ticket.", guild_ids=[id_do_servidor],
default_member_permissions=disnake.Permissions(manage_guild=True)
)
async def setupticket(
self, inter: disnake.AppCmdInter,
channel: disnake.TextChannel = commands.Param(name="canal", default=None),
):
if not channel:
channel = inter.channel
await inter.response.defer(ephemeral=True)
embed = disnake.Embed(
description="Crie seu ticket aqui",
color=inter.guild.me.color
)
embed.set_image(url="https://media.discordapp.net/attachments/480195401543188483/987168569450201108/ticket.png")
msg = await channel.send(
embed=embed,
components=[
disnake.ui.Select(
placeholder="Selecione um tipo de ticket:",
custom_id="ticket_controller",
min_values=0, max_values=1,
options=[
disnake.SelectOption(emoji="⚠️", label="Reportar Usuário"),
disnake.SelectOption(emoji="💡", label="Sugestão"),
disnake.SelectOption(emoji="🐛", label="Reportar Bug"),
]
)
]
)
await inter.edit_original_message(
embed=disnake.Embed(
color=inter.guild.me.color,
description=f"**Sistema de [ticket]({msg.jump_url}) configurado com sucesso!**"
)
)
@commands.slash_command(name="fecharticket", guild_ids=[id_do_servidor])
async def closeticket(self, inter: disnake.AppCmdInter):
if not isinstance(inter.channel, disnake.Thread) or not inter.channel.name.endswith(" - ticket"):
await inter.send("Este comando só pode ser usado em um ticket em aberto", ephemeral=True)
return
role = inter.guild.get_role(id_do_cargo_mod)
if not inter.author.guild_permissions.manage_guild or (role and role not in inter.author.roles):
await inter.send("Você não tem autorização para usar este comando aqui!", ephemeral=True)
return
await inter.send("ticket fechado com sucesso", ephemeral=True)
await inter.channel.edit(archived=True)
@commands.Cog.listener("on_dropdown")
async def open_ticket(self, inter: disnake.MessageInteraction):
if inter.data.custom_id != "ticket_controller":
return
if not inter.values:
await inter.response.defer()
return
ticket: Optional[disnake.Thread] = None
ticket_type = inter.data.values[0]
for thread in inter.channel.threads:
if str(inter.author.id) in thread.name and ticket_type.lower() in thread.name.lower():
if thread.archived:
ticket = thread
break
else:
await inter.send(
embed=disnake.Embed(
color=inter.guild.me.colour,
description=f"**Você já possui um [ticket]({thread.jump_url}) em aberto!**"
), ephemeral=True
)
return
if not ticket:
async for thread in inter.channel.archived_threads(limit=100):
if str(inter.author.id) in thread.name and ticket_type.lower() in thread.name.lower():
ticket = thread
if ticket:
await ticket.edit(archived=False)
await inter.send(
embed=disnake.Embed(
color=inter.guild.me.colour,
description=f"**seu [ticket]({ticket.jump_url}) foi reaberto.**"
),
ephemeral=True
)
else:
if inter.channel.id not in self.ticket_channel_ids:
self.ticket_channel_ids.add(inter.channel.id)
thread = await inter.channel.create_thread(
name=f"{inter.author.name} - {inter.author.id} ({ticket_type}) - ticket",
type=disnake.ChannelType.private_thread,
auto_archive_duration=10080
)
await inter.send(
embed=disnake.Embed(
description=f"**Seu [ticket]({thread.jump_url}) foi criado com sucesso!**",
color=inter.guild.me.colour,
),
ephemeral=True
)
await thread.send(f"{inter.author.mention} envie suas mensagens aqui.\n<@&{id_do_cargo_mod}>")
def setup(bot: commands.Bot):
bot.add_cog(TicketSystem(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment