-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
275 lines (227 loc) · 12.5 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
import disnake
import datetime
from disnake.ext import commands
from disnake_components import Select, SelectOption, ComponentsBot
from disnake import Button, ButtonStyle
import config
# Bot prefix
bot = ComponentsBot('!', help_command=None)
@bot.event
async def on_ready():
members = 0
for guild in bot.guilds:
members += guild.member_count - 1
await bot.change_presence(
activity=disnake.Activity(
type=disnake.ActivityType.watching,
# Bot status
name=f'{members} members'
)
)
print('Ready to support ✅')
# Ticket command
@bot.command()
@commands.has_permissions(administrator=True)
async def ticket(ctx):
await ctx.message.delete()
# Embed title and description
embed = disnake.Embed(title='Tickets', description='Welcome to tickets system.', color=config.embed_color)
# Embed image
embed.set_image(url='https://i.imgur.com/FoI5ITb.png')
await ctx.send(
embed=embed,
# Embed button
components=[
Button(
style=ButtonStyle.green,
label="Create a ticket",
emoji='🔧'
).custom_id('Ticket')
]
)
@bot.event
async def on_button_click(interaction):
canal = interaction.channel
canal_logs = interaction.guild.get_channel(config.id_channel_ticket_logs)
# Select function
if interaction.component.custom_id == "Ticket":
await interaction.send(
components=[
Select(
placeholder="How can we help you?",
options=[
SelectOption(label="Question", value="question", description='If you have a simple question.',
emoji='❔'),
SelectOption(label="Help", value="help", description='If you need help from us.',
emoji='🔧'),
SelectOption(label="Report", value="report", description='To report a misbehaving user.',
emoji='🚫'),
],
).custom_id('menu')
]
)
# Call staff function
elif interaction.component.custom_id == 'call_staff':
embed_llamar_staff = disnake.Embed(
description=f"🔔 {interaction.author.mention} has called the staff.", color=config.embed_color)
await canal.send(f'<@&{config.id_staff_role}>', embed=embed_llamar_staff, delete_after=20)
# Close ticket function
elif interaction.component.custom_id == 'close_ticket':
embed_cerrar_ticket = disnake.Embed(
description=f"⚠️ Are you sure you want to close the ticket?", color=config.embed_color)
await canal.send(interaction.author.mention, embed=embed_cerrar_ticket,
components=[
[
Button(custom_id='close_yes', label="Yes", style=ButtonStyle.green),
Button(custom_id='close_no', label="No", style=ButtonStyle.red)
]
])
# Ticket logs function
elif interaction.component.custom_id == 'close_yes':
await canal.delete()
embed_logs = disnake.Embed(title="Tickets", description=f"", timestamp=datetime.datetime.utcnow(),
color=config.embed_color)
embed_logs.add_field(name="Ticket", value=f"{canal.name}", inline=True)
embed_logs.add_field(name="Closed by", value=f"{interaction.author.mention}", inline=False)
embed_logs.set_thumbnail(url=interaction.author.avatar_url)
await canal_logs.send(embed=embed_logs)
elif interaction.component.custom_id == 'close_no':
await interaction.message.delete()
@bot.event
async def on_select_option(interaction):
if interaction.component.custom_id == "menu":
guild = interaction.guild
category = disnake.utils.get(interaction.guild.categories, id=config.id_category)
rol_staff = disnake.utils.get(interaction.guild.roles, id=config.id_staff_role)
# Select option | Question
if interaction.values[0] == 'question':
# Creating ticket channel | Question
channel = await guild.create_text_channel(name=f'❔┃{interaction.author.name}-ticket', category=category)
# Ticket channel permissions | Question
await channel.set_permissions(interaction.guild.get_role(interaction.guild.id),
send_messages=False,
read_messages=False)
await channel.set_permissions(interaction.author,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True)
await channel.set_permissions(rol_staff,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True,
manage_messages=True)
await interaction.send(f'> The {channel.mention} channel was created to solve your questions.',
delete_after=3)
# Inside the ticket | Question
# Embed inside the ticket | Question
embed_question = disnake.Embed(
title=f'Question - ¡Hi {interaction.author.name}!',
description='In this ticket we have an answer to your question.\n\nIf you cant get someone to help you, press the button `🔔 Call staff`..',
color=config.embed_color)
embed_question.set_thumbnail(url=interaction.author.avatar_url)
await channel.send(interaction.author.mention, embed=embed_question,
# Embed buttons inside the ticket | Question
components=[
[
Button(custom_id='close_ticket', label="Close ticket", style=ButtonStyle.red,
emoji='🔐'),
Button(custom_id='call_staff', label="Call staff", style=ButtonStyle.blue,
emoji='🔔')
]
])
# Select option | Help
elif interaction.values[0] == 'help':
# Creating ticket channel | Help
channel = await guild.create_text_channel(name=f'🔧┃{interaction.author.name}-ticket', category=category)
# Ticket channel permissions | Help
await channel.set_permissions(interaction.guild.get_role(interaction.guild.id),
send_messages=False,
read_messages=False)
await channel.set_permissions(interaction.author,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True)
await channel.set_permissions(rol_staff,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True,
manage_messages=True)
await interaction.send(f'> The {channel.mention} channel was created to help you.', delete_after=3)
# Inside the ticket | Help
# Embed inside the ticket | Help
embed_question = disnake.Embed(
title=f'Help - ¡Hi {interaction.author.name}!',
description='In this ticket we can help you with whatever you need.\n\nIf you cant get someone to help you, press the button `🔔 Call staff`.',
color=config.embed_color)
embed_question.set_thumbnail(url=interaction.author.avatar_url)
await channel.send(interaction.author.mention, embed=embed_question,
# Embed buttons inside the ticket | Help
components=[
[
Button(custom_id='close_ticket', label="Close ticket", style=ButtonStyle.red,
emoji='🔐'),
Button(custom_id='call_staff', label="Call staff", style=ButtonStyle.blue,
emoji='🔔')
]
])
# Select option | Report
elif interaction.values[0] == 'report':
# Creating ticket channel | Report
channel = await guild.create_text_channel(name=f'🚫┃{interaction.author.name}-ticket', category=category)
# Ticket channel permissions | Report
await channel.set_permissions(interaction.guild.get_role(interaction.guild.id),
send_messages=False,
read_messages=False)
await channel.set_permissions(interaction.author,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True)
await channel.set_permissions(rol_staff,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True,
manage_messages=True)
await interaction.send(f'> The {channel.mention} channel was created to report to the user.',
delete_after=3)
# Inside the ticket | Report
# Embed inside the ticket | Report
embed_question = disnake.Embed(
title=f'Report - ¡Hi {interaction.author.name}!',
description='In this ticket we can help you with your report.\n\nIf you cant get someone to help you, press the button `🔔 Call staff`.',
color=config.embed_color)
embed_question.set_thumbnail(url=interaction.author.avatar_url)
await channel.send(interaction.author.mention, embed=embed_question,
# Embed buttons inside the ticket | Report
components=[
[
Button(custom_id='close_ticket', label="Close ticket", style=ButtonStyle.red,
emoji='🔐'),
Button(custom_id='call_staff', label="Call staff", style=ButtonStyle.blue,
emoji='🔔')
]
])
bot.run(config.TOKEN)