Pepper is a discord bot I made a while back to learn. Its written in C#. It's not a public bot yet, but has shards implemented.
Its got everything I wanted it to have when I started to work on it so I've haulted progress on it. I may come back to add a few things here and there.
- General Info
- Technologies
- Setting Up
- Plans for the future
Modules :
Module | Description |
---|---|
General | General commands including commands for server configuration and more. |
Moderation | Moderation Commands. |
Soft Moderation | Soft Moderation commands. |
Games | Commands to play games such as UNO and Battleship with other server members. |
Fun | Commands for general fun! Troll users and use reddit based commands. |
Music | Commands to play music on discord. |
Images | Image Manipulation! Make memes with pre-built and and manipulate user profiles! |
Math | Simple math commands such as solving and graphing equations. |
Currency | A currency system! |
AIChat | An AI chat module for small talk and more! |
Does not have seperate prefix', Im not planning on adding it anytime soon either.
- Each server has a configuration and modules can be configured based on the needs of the server.
- Moderation and Soft Moderation modules connected to a database. All moderation events (bans, kicks, mutes etc.) are stored in a database and can be accessed at any time. Pepper contains server configureable filtered words, custom commands and rules. Moderators and Administrators are enforced at different levels.
- Music Module to play songs from Youtube or Soundcloud using Lavalink. Each server has its own player to handle music. Only one player can be registered for a server.
- A Dynamic Games module set up in a way which makes it easy to add new games and maintain scalability.
- An Image module which can be built open to manipulate gifs and videos and more and set up in a way which makes migration from one package to another easy.
- Fun module with configurable and Reddit based commands. All reddit commands are NSFW enforced.
- An AIChat module which uses Dialogflow to create an enhanced AI chat experiance.
- Commands to perform basic mathematical operations such as solving and graphic equations.
- An expandable currency system connected to a database. Boosts, items, tools, jobs and more are set up dynamically and can be scaled easily. More features can also be added to the database with ease.
- C# 8
- .NETCore 3.1
- .NETStandard 2.1
- DSharpPlus 4.0.1
- Microsoft.EntityFrameWorkCore 5.0.7
- DSharpPlus.LavaLink
- SQlite
- Reddit.NET
- Denzven Graphing API
- Dialogflow
- Magick.NET
- StoryScript
(I honestly don't know what goes here so I just put everything)
- Clone the repo on your local system using the following command line
$ git clone https://github.com/kunrex/Pepper.bot
- Open a new Browser window and search Discord Developer Portal.
- Navigate to the Applications window and select
New Application
. This application is your bot - Give the application a name and hit
Create
. You can now fill in the other details of the bot like the description and give the bot a pfp. - Navigate to
Bot
tab, clickClick To Reveal Token
and copy whatever appears. This is the token for your discord bot and is used in code. DO NOT show anyone this token.
Pepper uses DSharpPlus.LavaLink for music commands.
Find the LavaLink.jar file at KunalsDiscordBot/Modules/Music
. open a cmd prompt or terminal instance at this path and run
java -jar Lavalink.jar
This runs the jar file.
The bot comes with a set up application.yaml
file to configure LavaLink so it should run locally on your device. You can look into LavaLinks repository or the DSharpPlus tutorial for more info.
Pepper uses Reddit.NET for all things reddit. This is primarily used in the FunModule but can be built upon for more complex Reddit related commands.
- Open up the Apps page on Reddit and hit
create an app
at the bottom. - Give the app a name and a description. Under
App Type
choosescript
. TheRedirect URL
can really be any valid URL. After that you can just hitCreate App
. - Its gonna redirect your page that looks something like this.
We need 2 things from here, your client app id
(The set of characters under personal use script
) and client secret
.
- Apart from those 2 we also need a
refreshToken
. Now I have to admit getting this is a bit trickier than the appId and secret. You can either follow the instructions at here or just use this simple link.
You can look into the Readme.md at KunalsDiscordBot/Reddit/
for more info on the Reddit implementation.
Pepper uses Dialogflow for NLP used in the AI chat module. You can follow the instructions to set up Dialogflow and to create a Dialogflow Agent
here. Pepper does use the API so make sure to install Cloud SDK
as well. Keep track of the JSON file downloaded containing the KEY of your project and the project ID of your Dialogflow agent as they are used in the primary config file
After you have Dialogflow set up, you can enable small talk for the agent. Go to the home page of your agent. On the sidebar in the left, scroll down till you find Small Talk
. Click it and enable it by checking the toggle called Enable
. You can now fill in various small talk responses that you want your agent to have.
Come back to the project on your system and find the folder called KunalsDiscordBot
and create a new json file called Config.json
exactly. You can change this name later if needed. This is gonna be the config file for the bot. Open the file and paste the following lines and fill in the appropriate values.
{
"Version": 1,
"DiscordConfig": {
"Token": "your discord bot token here, the same on you copied from the discord developers portal",
"Prefixes": [ "prefixes here" ],
"Dms": false,
"TimeOut": 60,
"ShardCount": 1,
"ActivityType": 0,
"ActivityText": "whatever should show up in your bots activity",
"ErrorLink": "Any image link, this image is used when an error occurs."
"WriteCommands": false,
"WriteLocation": "The file location where you want to write all the commands to"
},
"LavalinkConfig": {
"Hostname": "127.0.0.1",
"Port": 2333,
"Password": "pepperrocks"
},
"RedditConfig": {
"AppId": "your reddit app id here",
"AppSecret": "your reddit app secret here",
"RefreshToken": "your reddit app refresh token here",
"PostLimit": 50
},
"ChatbotConfig": {
"ProjectId": "Your Dialogflow project ID",
"GoogleCreedentialsVariable": "GOOGLE_APPLICATION_CREDENTIALS",
"GoogleCredentialsPath": "The path to your Dialogflow Key JSON",
"TimeOutime" : 30
}
}
Discord Config
Token
: The client token for your bot.Prefixes
: The default prefixes for your bot.Dms
: Are commands sent through direct messages are processed or notTimeOut
: The default timeout (in seconds) for the interactivity for your bot. The value be overriden wherever nececarry but defaults to the value here.ShardCount
: The number of shards for your bot.ActivityType
: The activity type that appears for your bot in discord, this is later converted to an enumActivityType
. The valid values for the activity types are below- 0 : Playing
- 1 : Streaming
- 2 : ListeningTo
- 3 : Watching
- 4 : Custom
- 5 : Competing
ActivityText
: The text that appears as your bots activityErrorLink
: The image that appears in the footer when an error occursWriteCommands
: Not related to the any code This value is for the website, it stores whether or not commands need to be written to a JSON file every time the program is run. This file is read to list all the commands on the website.WriteLocation
: Not related to any code This value is for the website, it stores the location of the file where all commands are written to. The commands are written in JSON format. This file is read to list all the commands on the website.
LavaLink Config
Hostname
: The name of the host used to host lava linkPort
: the port number on which to host lavalinkPassword
: The LavaLink password, note changing the password here also requires you to change the password in theapplication.yaml
file atKunalsDiscordBot/Modules/Music
Reddit Config
AppId
: The app Id of your reddit appAppSecret
: The app secret of your reddit appRefreshToken
: The refresh token of your reddit appPostLimit
: The maximum amount of posts the bot collects from registered subreddits.
Chatbot Config
ProjectId
: The project ID of your Dialogflow projectGoogleCreedentialsVariable
: The name of the environment variable used by Dialogflow. Make sure this isGOOGLE_APPLICATION_CREDENTIALS
only.GoogleCredentialsPath
: The path to the JSON file contianing the key of your Dialogflow project (The one you downloaded while creating the service account for your Dialgflow agent).TimeOutime
: The maximum time (in seconds) after which a Dialogflow processing request is cancelled.
The github repo does not include the Migrations folder nor does it include the Database itself. So you need to create them when you clone the repo as its used in the currency system and for general server configurations..
Copy the path of the folder called KunalsDiscordBot
and open a cmd prompt or terminal instance at this path.
First make sure you have dotnet-ef installed by running.
dotnet tool install -global dotnet-ef
Also make sure you have the package Microsoft.EntityFrameWorkCore.Design
installed through the nuget manager or the following cmd line
dotnet add package Microsoft.EntityFrameWorkCore.Design
We can now create a migration using
dotnet-ef migrations add InitialCreate -p ../DiscordBotDataBase.Dal.Migrations/DiscordBotDataBase.Dal.Migrations.csproj --context DiscordBotDataBase.Dal.DataContext
This line, creates a new migration called InitialCreate
in the project called DiscordBotDataBase.Dal.Migrations
.
the last part of the line line uses the DbContext DataContext
in the namespace DiscordBotDataBase.Dal
.
If you have done everything correctly and the build succeedes its time to actually create our database using the following command
dotnet-ef database update InitialCreate -p ../DiscordBotDataBase.Dal.Migrations/DiscordBotDataBase.Dal.Migrations.csproj --context DiscordBotDataBase.Dal.DataContext
Its the same as before but instead of migrations add
, we use database update
. The other parameters are the same.
If you get no errors and the build succeedes then you should see a file called Data.db
appear in the folder called KunalsDiscordBot
considering you haven't changed anything.
If you do then great work! The databse has been set up succesfully.
Any time you make any chages to the Database Models you will be needed to run these last 2 commands in that specific order to add the new migrations and update the database
Although you would change the names of the Migrations on each update. for this example we used InitialCreate
. You would put in a different value every time you create something new.
You can look into the Microsoft Docs for SQLite for more info.
This project was a lot of fun, it was great to learn but I have moved on to other projects as is the natural state of things. Regardless it provides my (as in the me writing this page) idea of what a discord bot should like.
For More info you can contact me on Discord