This is a personal project that contains a Discord bot and a backend API for a PostgreSQL database to be used by the bot for its functions. It is meant as a base that should be relatively easy to add more functionality into.
The project was programmed in C# using Visual Studio Community 2022, and the database used is PostgreSQL 15.
The bot uses the Discord.NET framework, and the backend API for the database uses ASP.NET Core and Entity Framework Core.
To get started, clone or download the project. You will also need to add your database connection string to the appsettings.json
in Backend/BackendAPI/BackendAPI
using the key Database:ConnectionString
. You will also need to add your Discord Bot Token,
database API URL, and an API key to Open Emoji API in the appsettings.json
in Bot/DiscordBot/DiscordBot
using the keys BotToken
, Database:apiUrl
and EmojiApiKey
. You can alternatively use the Secret Manager
tool and add these to the secrets in the BackendAPI and DiscordBot projects (recommended).
- Update your database by using the
Update-Database
command in the Package Manager Console when you have the BackendAPI project open in Visual Studio. - Import the
8BallResponses.csv
from the repository root to yourMagic8BallResponse
table in your database to populate it with default values.
After following these instructions, run your BackendAPI and then DiscordBot and you should be able to see the bot come online on Discord and use the commands. (Assuming I haven't forgotten anything)
/ping
- The bot responds with "pong" and displays its current client latency./8ball [question] [ephemeral]
- The bot responds with a magic 8-ball style answer. If you use thequestion
parameter you can type a question that the bot will include in its response. If you set theephemeral
parameter toTrue
the response will be sent in a message that will only be displayed to you.
/event create [title] [date] [description=""]
- Create a new event with the giventitle
,date
and optionaldescription
. Users can add votes to the event with reactions./event list [ephemeral=True]
- List all the existing events in the database. The list is sent as ephemeral by default, but can be sent as normal withephemeral
set toFalse
./event get [id]
- Send a message containing the event with givenid
. This message can be reacted to and will modify the votes on the event accordingly./event delete [id]
- Delete the event with givenid
. Will prompt for confirmation.
- GET
/api/Magic8Ball
Get all the magic 8-ball responses - GET
/api/Magic8Ball/random/weighted
Get a single magic 8-ball response with the same random distribution as an original magic 8-ball (50% affirmative, 25% negative, 25% noncommittal) - POST
/api/Magic8Ball
Post a new magic 8-ball response - DELETE
/api/Magic8Ball/{id}
Delete the magic 8-ball response with the givenid
- GET
/api/Events/
Get all events in database - GET
/api/Events/{id}
Get event with givenid
- GET
/api/Events/{id}/Votes
Get all votes on an event with givenid
- GET
/api/Events/GetIdFromMessage/{messageId}
Get the event id that the given Discord message with idmessageId
corresponds (if exists) - POST
/api/Events
Post a new event - POST
/api/Events/{id}/Votes
Post a vote to an event - POST
/api/Events/{id}/Messages
Post a newmessageId
for the event with givenid
- DELETE
/api/Events/{id}
Delete event with the givenid
- DELETE
/api/Events/{id}/Votes/{emoji}/{userId}
Delete a vote on the event with givenid
for the Discord custom emoji id or unicode emojiemoji
from the Discord user with iduserId
- A web front end that contains instructions on the commands
- Ability to configure and manage commands from the web front end (e.g. add new magic 8-ball responses)
- Authentication to the front end with Discord account
- Adding separation by Discord server to commands that should have it (events, custom magic 8-ball responses)
- Ability for the bot to remind of events ahead of time