A discord ticket system with PostgreSQL.
This is not supposed to be a copy and paste exercise, if you want to recreate the system, learn python first.
If you have any improvement suggestions feel free to contact me.
If you are completly new to discord.py or generally python - DO NOT JUST copy the code - study the syntax first and try slightly easier projects.
- Python 3.8.6 or higher
- discord.py (Tested with version 1.6.0)
- PostgreSQL Database (I am using a local PostgreSQL Database)
- asyncpg
-
Download the installer from the website.
-
After the download is complete start the installation by double-clicking on the .exe.
-
A Setup-Window should show up. Just keep clicking on NEXT until the password window.
-
Choose a good and secure password and remember it!
-
You can use the default settings for the next two windows.
-
Now start the installation.
-
After the installation is finished you shuold see this windows. You dont need to launch Stack-Builder - just click on finish.
-
Now click on Windows and search for PostgreSQL. Open the folder and click on pgAdmin4.
-
After it loads, it asks for the password you used during the installation.
-
Click on Servers on the left side and open Databases. You can see that one with the name postgres already exists.
-
Right-Click on Databases and select Create Database. Name it PostgreSQL-Tickets and click on save.
-
The Database should appear on the left side. Open it and scroll down to Schemas. If you have Schemas open, you will find Tables below.
-
Right-Click on Tables and create a new one. Call it tickets and add two columns named
guild_id
(PK) andticket_id
. Like this. -
Add another Table named requests with three columns named
guild_id
,channel_name
andchannel_id
. Like this. -
Now the database setup is finished - dont close it now you will need it later again.
-
Go on the discord developer portal and make a new application. Now create a new bot and add him to your server.
-
Open
data.json
and fill in your bot-token and db-password (The one you created at the beginning) -
Start the bot and type
?ticket
in your ticket-channel. A message like this should show up. -
Now copy the ID of your server and the message you just created and fill it in the database. Your DB should look like this.
-
If you are done, restart the bot and click on the 📩. You should see a new channel with a message inside.
@commands.command()
@commands.has_permissions(administrator=True)
async def ticket(self, ctx):
embed = discord.Embed(
title="Would you like to create a ticket?",
description="If you have any questions or concerns create a new ticket by clicking on the emoji below this message.",
color=0xf7fcfd)
embed.add_field(name="Do you want to report someone?", value="Please contact a supporter or moderator directly!", inline=True)
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/771635939700768769/773121323341578250/external-content.duckduckgo.com.png")
embed.set_author(name="TiLiKas-Tickets")
msg = await ctx.send(embed=embed)
await msg.add_reaction("📩")
I would recommend to change the authors-name (TiLiKas-Tickets)
There are three options for the message in the ticket channel.
✅ -> Claim the ticket (The creator of the ticket cant claim it)
⛔ -> Mention every supporter (Does not do anything right now - I'm at it!)
🔒 -> Close the ticket - the channel will be delete after 10 seconds.
After clicking on the lock, the channel will be deleted and a new channel named ticket-log will appear.
If you did everything correctly your bot should work like in the examples!
Still questions? Join my discord server.
I am not going to explain how it works with other databases!
As I wrote at the beginning, this tutorial is not for beginners.