Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Running the bot

Felipe Giraldo edited this page Jun 17, 2022 · 8 revisions

Up to this part of the guide the bot should be working, with the default values of course, but if up to this part your bot is working it means that you have completed the previous steps well.

Ticket channel

Now we will create the channel where our message will go to create tickets.

image

Ticket command

In the ticket channel we are going to execute the command tb!ticket (remember that tb! is the default prefix, if you changed it you put its respective prefix) and the bot will reply this:

image

@bot.command()
@commands.has_permissions(administrator=True)
async def ticket(ctx):
    await ctx.message.delete()

    embed = discord.Embed(title ='Tickets', description ='Welcome to tickets system.', color=embed_color) 
    embed.set_image(url='https://i.imgur.com/FoI5ITb.png')
    await ctx.send(
        embed = embed,
        components = [
            Button(
                custom_id = 'Ticket',
                label = "Create a ticket",
                style = ButtonStyle.green,
                emoji ='πŸ”§')
        ]
    )

Testing the bot

Select function

image

image

    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")])

When one of the options is selected, the bot will send a confirmation message when the respective ticket is created, also mentioning its executor in the ticket.

image

        if interaction.values[0] == 'question':
            channel = await guild.create_text_channel(name=f'❔┃{interaction.author.name}-ticket', category=category)
            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

image

image

            embed_question = discord.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=embed_color)
            embed_question.set_thumbnail(url=interaction.author.avatar_url)

            await channel.send(interaction.author.mention, embed=embed_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 ='πŸ””')]])

Call staff function

image

    elif interaction.component.custom_id == 'call_staff':

        embed_llamar_staff = discord.Embed(description=f"πŸ”” {interaction.author.mention} has called the staff.", color=embed_color)
        await canal.send(f'<@&{id_staff_role}>', embed=embed_llamar_staff, delete_after= 20)

Close ticket function

image

    elif interaction.component.custom_id == 'close_ticket':

        embed_cerrar_ticket = discord.Embed(description=f"⚠️ Are you sure you want to close the ticket?", color=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

When the ticket has been closed, a message will be automatically sent to the ticket log channel with basic ticket information.

image

    elif interaction.component.custom_id == 'close_yes':

        await canal.delete()
        embed_logs = discord.Embed(title="Tickets", description=f"", timestamp = datetime.datetime.utcnow(), color=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)