-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
327 lines (225 loc) · 11.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
"""
██████╗░ ░░░░░░ ████████╗██╗░█████╗░██╗░░██╗███████╗████████╗
██╔══██╗ ░░░░░░ ╚══██╔══╝██║██╔══██╗██║░██╔╝██╔════╝╚══██╔══╝
██║░░██║ █████╗ ░░░██║░░░██║██║░░╚═╝█████═╝░█████╗░░░░░██║░░░
██║░░██║ ╚════╝ ░░░██║░░░██║██║░░██╗██╔═██╗░██╔══╝░░░░░██║░░░
██████╔╝ ░░░░░░ ░░░██║░░░██║╚█████╔╝██║░╚██╗███████╗░░░██║░░░
╚═════╝░ ░░░░░░ ░░░╚═╝░░░╚═╝░╚════╝░╚═╝░░╚═╝╚══════╝░░░╚═╝░░░
"""
"""
Version = 1.2
COMMANDS:-
- !dttcreate (reason) : to be create the ticket
- !dtclose (reason) : to close the ticket (ticket only closed by ticket admin or ticket manager, user just only can make a close request)
- !tsetadmin (member) : to set a ticket admin with role name 'Ticket Admin' (Ticket Manager can use this command)
- !tsetmanager (member) : to set a ticket manager with role name 'Ticket Manager' (User with adminstrator permission can use this command)
Extra Feature:-
- !tservice (extra feature) : you can enable or disable (on/off) ticket service so noone can abuse it by make ticket channels.
- !tsetrole :
- Ticket channel cannot be create more than 10 ticket channels.
- tsetrole (ticket manager role) (ticket admin role) : you can set desire role for ticket manager and ticket admin
"""
import discord
from discord.ext import commands
from discord import Intents
import json
# --- Variable ---
max_ticket_channel = 10
ticket_service = True
ticket_manager_role = None
ticket_admin_role = None
bot = commands.Bot(command_prefix='!d', case_insensitive=True, intents=Intents.all())
@bot.event
async def on_ready():
# --- Bot Rich Presence ---
game = discord.Game("Created by DeViL#7091") # You can change rich presence
await bot.change_presence(status=discord.Status.online, activity=game)
print(f'Bot is online.\n Bot Name: {bot.user}!')
# ----- TICKET COMMANDS -----
# --- Ticket Create (tcreate) ---
@bot.command()
async def tcreate(ctx, *,reason:str):
if ticket_service == True:
total_ticket_channel = 0
for channel in ctx.guild.channels:
if "ticket" in str(channel):
total_ticket_channel += 1
global max_ticket_channel
if total_ticket_channel >= max_ticket_channel:
return await ctx.send(f"{ctx.author.mention} Please wait some time there are maxmimum ticket created!")
ticket_channel = await ctx.guild.create_text_channel(f'ticket-{ctx.author.discriminator}')
overwrite = discord.PermissionOverwrite()
overwrite.send_messages = False
overwrite.read_messages = False
await ticket_channel.set_permissions(ctx.guild.get_role(ctx.guild.id), overwrite=overwrite)
await ticket_channel.set_permissions(ctx.author, read_messages=True, send_messages=True)
for role in ctx.guild.roles:
if ticket_manager_role in str(role) or ticket_admin_role in str(role):
await ticket_channel.set_permissions(role, read_messages=True, send_messages=True)
await ticket_channel.send(f"{ctx.author.mention}, Ticket has been created!")
# Embed Message
embed = discord.Embed(title="Ticket", description="Please wait support will be with you shortly.", colour=ctx.author.colour)
embed.set_thumbnail(url=ctx.bot.user.avatar_url)
embed.add_field(name="Created By:", value=f"{ctx.author.name}", inline=True)
embed.add_field(name="Reason:", value=f"{reason}", inline=True)
embed.set_footer(text="D-Ticket", icon_url=ctx.bot.user.avatar_url)
await ticket_channel.send(embed=embed)
else:
await ctx.send(f"{ctx.author.mention}, Currently ticket service is off by admins. Please try again later or contact to server admin!")
# --- Ticket Close (tclose) ---
@bot.command()
async def tclose(ctx, *, reason:str):
if is_ticket_manager(ctx) == True or is_ticket_admin(ctx) == True:
if "ticket" in ctx.channel.name:
return await ctx.channel.delete(reason=reason)
else:
return await ctx.send("Please use this command only in ticket channels.")
else:
for tchannel in ctx.guild.channels:
if str(ctx.author.discriminator) in str(tchannel.name):
if str(ctx.channel.name) in str(tchannel.name):
await tchannel.set_permissions(ctx.author, read_messages=False, send_messages=False)
return await tchannel.send(f"{ctx.author.name} has requested to close the ticket. Reason: {reason}")
else:
return await tchannel.send(f"Please use this command here to close the ticket. {tchannel.mention}")
else:
return await ctx.channel.send("Your ticket is not found or ticket has already closed.")
# --- Setup (tsetrole) ---
@bot.command()
@commands.has_permissions(administrator=True)
async def tsetrole(ctx, mrole:discord.Role, arole:discord.Role):
# -- Manager Role --
for managerrole in ctx.guild.roles:
if str(mrole.name) == str(managerrole.name):
global ticket_manager_role
ticket_manager_role = str(managerrole.name)
break
else:
return await ctx.send(f"{ctx.author.mention} Failed to set ticket manager role. No role name found {mrole}")
# -- Admin Role --
for adminrole in ctx.guild.roles:
if str(arole.name) == str(adminrole.name):
global ticket_admin_role
ticket_admin_role = str(adminrole.name)
break
else:
return await ctx.send(f"{ctx.author.mention} Failed to set ticket admin role, No role name found {mrole} or {arole}")
embed = discord.Embed(title="Role Set", description=f"Successfully set the ticket roles.", colour=ctx.bot.user.colour)
embed.set_thumbnail(url=ctx.bot.user.avatar_url)
embed.add_field(name="Ticket Manager:", value=f"{ticket_manager_role}", inline=True)
embed.add_field(name="Ticket Admin:", value=f"{ticket_admin_role}", inline=True)
embed.set_footer(text="D-Ticket", icon_url=ctx.bot.user.avatar_url)
return await ctx.send(embed=embed)
# --- Set Ticket Admin (tsetadmin) ---
@bot.command()
@commands.has_permissions(send_messages=True)
async def tsetadmin(ctx, member:discord.Member):
if ticket_admin_role == None:
await ctx.send(f"{ctx.author.mention} Ticket admin role is not set. Please set it by `tsetrole`")
if ctx.author.name == member.name:
return await ctx.send(f"{ctx.author.mention} You cannot give ticket admin role to yourself")
else:
for mrole in ctx.author.roles:
if ticket_manager_role in str(mrole):
for arole in member.roles:
if ticket_admin_role in str(arole):
return await ctx.send(f"{ctx.author.mention}, Mention member already have ticket admin role.")
else:
try:
await member.add_roles(discord.utils.get(ctx.guild.roles, name=ticket_admin_role),reason=None, atomic=True)
await ctx.send(f"{member.mention}, You are now ticket admin.")
return await ctx.send(f"{ctx.author.mention}, `{member.name}` is now ticket admin.")
except Exception as error:
await ctx.send(f"{ctx.author.mention}, Something went wrong!")
return print(f"Error (tsetadmin): {error}")
else:
await ctx.send(f"{ctx.author.mention}, You don't have access to set a ticket admin")
# --- Set Ticket Manager (tsetmanager) ---
@bot.command()
@commands.has_permissions(manage_roles=True)
async def tsetmanager(ctx, member:discord.Member):
if ticket_manager_role == None:
await ctx.send(f"{ctx.author.mention} Ticket manager role is not set. Please set it by `tsetrole`")
if ctx.author.name == member.name:
return await ctx.send(f"{ctx.author.mention}, You cannot give manager role to yourself.")
else:
for role in member.roles:
if ticket_manager_role in str(role):
return await ctx.send(f"{ctx.author.mention}, Mention member already have ticket manager role.")
else:
try:
await member.add_roles(discord.utils.get(ctx.guild.roles, name=ticket_manager_role),reason=None, atomic=True)
await ctx.send(f"{member.mention}, You are ")
return await ctx.send(f"{ctx.author.mention}, `{member.name}` is now ticket manager")
except Exception as error:
await ctx.send(f"{ctx.author.mention}, Something went wrong!")
return print(f"Member ticket admin add role error: {error}")
# --- Service [On/Off] (tservice) ---
@bot.command()
async def tservice(ctx, state:str):
global ticket_service
if ticket_manager_role != None:
if is_ticket_manager(ctx) == True:
if state == "on" or state == "enable":
ticket_service = True
return await ctx.send(f"{ctx.author.mention}, Ticket service is set to `{state}`")
elif state == "off" or state == "disable":
ticket_service = False
return await ctx.send(f"{ctx.author.mention}, Ticket service is set to `{state}`")
else:
await ctx.send(f"{ctx.author.mention}, You have send invaild input.")
await ctx.send(f"Correct Usage: tservice [on/off] or [enable/disable]")
else:
await ctx.send(f"{ctx.author.mention}, You don't have permission to use this command.")
else:
return await ctx.send(f"Ticket Manager Role is not set. Please set the role first by `tsetrole [@role (Ticket Manager Role)] [@role (Ticket Admin Role)]`")
# ----- ERROR HANDLER -----
# --- Ticket Create Error (tcreate) ---
@tclose.error
async def tcreate_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument) or isinstance(error, commands.BadArgument):
await ctx.send(f"{ctx.author.mention} Correct Usage: `tcreate [reason]`")
# --- Ticket Close Error (tclose) ---
@tclose.error
async def tclose_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument) or isinstance(error, commands.BadArgument):
await ctx.send(f"{ctx.author.mention} Correct Usage: `tclose [reason]`")
# --- Set Role (tsetrole) ---
@tsetrole.error
async def tsetrole_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send(f"{ctx.author.mention} You don't have permission to use this command.")
if isinstance(error, commands.MissingRequiredArgument) or isinstance(error, commands.BadArgument):
await ctx.send(f"{ctx.author.mention} Correct Usage: `tsetrole [@role (Ticket Manager Role)] [@role (Ticket Admin Role)]`")
# --- Ticket Set Admin (tsetadmin) ---
@tsetadmin.error
async def tsetadmin_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument) or isinstance(error, commands.BadArgument):
await ctx.send(f"{ctx.author.mention} Correct Usage: `tsetadmin [@member]`")
# --- Ticket Set Manager (tsetmanager) ---
@tsetmanager.error
async def tsetmanager_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send(f"{ctx.author.mention} You don't have permission to use this command.")
if isinstance(error, commands.MissingRequiredArgument) or isinstance(error, commands.BadArgument):
await ctx.send(f"{ctx.author.mention} Correct Usage: `!dtsetmanager [(mention)member]`")
# ----- FUNCTIONS -----
# --- is_ticket_manager ---
def is_ticket_manager(ctx):
for role in ctx.author.roles:
if ticket_manager_role in str(role):
return True
else:
return False
# --- is_admin_manager ---
def is_ticket_admin(ctx):
for role in ctx.author.roles:
if ticket_admin_role in str(role):
return True
else:
return False
# --- Token Json ---
with open("./config.json", 'r') as JsonTokenFile:
token_data = json.load(JsonTokenFile)
TOKEN = token_data["TOKEN"]
bot.run(TOKEN) # Token as a string