Discord.PY Ticket Bot
Archiviert 2 years ago
N
Naainz
Verified
I'm making a bot on discord.py, I've been trying to add a ticket command, but for some reason - i make it so that when I run !create_ticket - it sends a embed to that channel with discord.Interaction buttons. . But the button's don't work... When they did work, they would always open a ticket from the person who originally ran !create_ticket -- which I don't want. I wanted the user who pressed the buttons to be able to have the ticket assigned to them: Any help would be appreciated.
```
class MyView(discord.ui.View):
def __init__(self, user):
super().__init__()
self.user = user
@discord.ui.button(label="Support", style=discord.ButtonStyle.blurple)
async def support(self, button: discord.ui.Button, interaction: discord.Interaction):
await self.create_ticket_channel(interaction.user, "Support")
await interaction.response.send_message("You have selected: Support", ephemeral=True)
@discord.ui.button(label="Application", style=discord.ButtonStyle.green)
async def application(self, button: discord.ui.Button, interaction: discord.Interaction):
ticket_channel = await self.create_ticket_channel(interaction.user, "Application")
await interaction.response.send_message("You have selected: Staff Application", ephemeral=True)
await self.application_questions(interaction.user, ticket_channel)
async def create_ticket_channel(self, user, ticket_type):
server = client.get_guild(944605334184529990)
category = discord.utils.get(server.categories, name="Ticket Channels")
if not category:
category = await server.create_category("Ticket Channels")
ticket_name = f"{ticket_type.lower()}-{user.name}"
ticket_channel = await server.create_text_channel(ticket_name, category=category, overwrites=overwrites)
# Define overwrites
overwrites = {
server.default_role: discord.PermissionOverwrite(read_messages=False),
user: discord.PermissionOverwrite(read_messages=True, send_messages=True),
server.get_role(MODERATOR): discord.PermissionOverwrite(read_messages=True, send_messages=True),
server.get_role(DESIGNER): discord.PermissionOverwrite(read_messages=True, send_messages=True),
server.get_role(DEVELOPER): discord.PermissionOverwrite(read_messages=True, send_messages=True),
server.get_role(ADMIN): discord.PermissionOverwrite(read_messages=True, send_messages=True),
}
ticket_channel = await server.create_text_channel(ticket_name, category=category, overwrites=overwrites)
mention_string = f"{user.mention}"
await ticket_channel.send(f"What may we help you with today {mention_string}? Please be patient as we get to you as soon as possible.")
# Update ticket cooldown for the user
ticket_cooldown[user.id] = datetime.datetime.now() + datetime.timedelta(minutes=5)
if ticket_type.lower() == 'application':
await self.application_questions(user, ticket_channel)
return ticket_channel
async def application_questions(self, user, channel):
def check(m):
return m.author == user and m.channel == channel
(private confidential information sorry)
```
