import discord from discord.ext import commands import random import datetime import time import platform import asyncio import json from pathlib import Path from discord.utils import get import cogs._json class TicketSystem(commands.Cog): def __init__(self, bot): self.bot = bot @commands.Cog.listener() async def on_ready(self): print(f"{self.__class__.__name__} Cog has been loaded\n-----") @commands.Cog.listener() async def on_raw_reaction_add(self, payload): message_id = payload.message_id guild_id = payload.guild_id guild = discord.utils.find(lambda g: g.id == guild_id, self.bot.guilds) member = discord.utils.find( lambda m: m.id == payload.user_id, guild.members) role = discord.utils.find(lambda r: r.name == 'Moderator', guild.roles) role2 = discord.utils.find(lambda r: r.name == 'Sale Team', guild.roles) notbot = member.id != self.bot.user.id if payload.emoji.name == '📨' and notbot: overwrites = { guild.default_role: discord.PermissionOverwrite(read_messages=False), guild.me: discord.PermissionOverwrite(read_messages=True), member: discord.PermissionOverwrite(read_messages=True, send_messages=True, attach_files=True), role: discord.PermissionOverwrite(read_messages=True), role2: discord.PermissionOverwrite(read_messages=True) } emoji = '📨' channel1 = self.bot.get_channel(payload.channel_id) message = await channel1.fetch_message(payload.message_id) await message.remove_reaction(emoji, member) ticketchnnel = await guild.create_text_channel(name=f"ticket - {member}", overwrites=overwrites, category=self.bot.get_channel(900411455508209685)) ticketembed = discord.Embed( title='**Ticket system**', description=f"נפתח על ידי {member.mention}", timestamp=datetime.datetime.now(), color=discord.Colour(0x001BFF)) ticketmsg = await ticketchnnel.send(embed=ticketembed) emoji2 = '🗑️' await ticketmsg.add_reaction(emoji2) if payload.emoji.name == '🗑️' and notbot: channel = await self.bot.fetch_channel(payload.channel_id) chekchannel = channel.name.startswith("ticket") chekchannel2 = channel.name.endswith("-ticket") if chekchannel or chekchannel2: await channel.delete() @commands.command() async def add(self, ctx, member: discord.Member): channel = ctx.channel chekchannel = ctx.channel.name.startswith("ticket") chekchannel2 = channel.name.endswith("-ticket") if chekchannel or chekchannel2: embed = discord.Embed( description=f'{member.mention} התווסף בהצלחה', color=discord.Colour(0x001BFF)) await ctx.channel.set_permissions(member, read_messages=True) await ctx.send(embed=embed) @commands.command() async def remove(self, ctx, member: discord.Member): channel = ctx.channel chekchannel = ctx.channel.name.startswith("ticket") chekchannel2 = channel.name.endswith("-ticket") if chekchannel or chekchannel2: embed = discord.Embed( description=f'{member.mention} נמחק בהצלחה', color=discord.Colour(0x001BFF)) await ctx.channel.set_permissions(member, read_messages=False) await ctx.send(embed=embed) @commands.command() async def rename(self, ctx, *, message=None): channel = ctx.channel chekchannel = ctx.channel.name.startswith("ticket") chekchannel2 = channel.name.endswith("-ticket") if chekchannel or chekchannel2: embed = discord.Embed( description=f'{channel.mention}שונה בהצלחה ל `{message}``', color=discord.Colour(0x001BFF)) await channel.edit(name=f"{message}-ticket") await ctx.send(embed=embed) @commands.command() async def close(self, ctx): channel = ctx.channel chekchannel = ctx.channel.name.startswith("ticket") chekchannel2 = channel.name.endswith("-ticket") if chekchannel or chekchannel2: closembed = discord.Embed( title='**Ticket system**', description='על מנת לסגור את הטיקט יש ללחוץ על הריאקט', color=discord.Colour(0x001BFF)) closemsg = await ctx.channel.send(embed=closembed) emoji3 = '🗑️' await closemsg.add_reaction(emoji3) def setup(bot): bot.add_cog(TicketSystem(bot))