SkillAgentSearch skills...

Berendbotje

Discord bot written in PHP to replace a number of bots in our server

Install / Use

/learn @b3r3nd/Berendbotje
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Berend Botje

<p align="center"> <a href="https://top.gg/bot/651378995245613056"> <img src="https://top.gg/api/widget/651378995245613056.svg"> </a> <a href="https://discord.gg/6vbxgfaUz6"> <img src="https://discordapp.com/api/guilds/1034615413725736970/widget.png?style=banner1" alt="Discord Banner 1"/> </a> </p>

Discord bot written in PHP using laravel and the DiscordPHP package. Initially created just for our own server but is now able to run on multiple servers. This project is still a work in progress and not everything might be completely user-friendly. Check the /help command in discord for more information.

  • Invite bot to your server -> https://discord.com/oauth2/authorize?client_id=651378995245613056&scope=bot
  • Any questions or support -> https://discord.gg/rVxJBbVNR7
  • Top gg link -> https://top.gg/bot/651378995245613056

Special thanks to

  • Justin & Stefan for ideas and mental support.
  • Angel for writing most of the Skyrim lines used in the MentionResponder.
  • Richard & Ricardo for bug testing and working out ideas.

Functionality

Short list of what this bot can do:

  • Everything is based on guild, can run on multiple servers with its own data
  • Role and permissions system with complete control to assign permissions as you see fit
  • Leveling by sending messages and hanging out in voice + commands to manage xp
  • Role Rewards based on levels
  • Custom level up messages
  • Extensive bot config where almost all settings can be changed
  • Enable / disable server invites through command to allow mods to use it (has separate permission)
  • User config where user can set specific settings for that guild
  • Extensive logging with ability to enable/disable each event individually
  • Adding flags to channels to for example not gain xp there, or not allow stickers, or only allow media
  • Automatic timeout detection to get a better overview of who has been timed out, why and how often
  • User blacklist where users can be added and prevented from using certain functions of the bot
  • Assign roles to users when they join the server
  • Custom welcome messages when people join the server
  • Add replies based on roles in the server when you mention the bot
  • Reminders - send a reminder every xx time in a certain channel
  • Add emotes as custom reactions to strings, when those strings are detected the bot will react with set emote
  • Add custom message commands with simple responses
  • Counting channel
  • Question of the day reminder tag
  • Count all emotes send in the server
  • Cringe counter where you can increase and decrease as people behave in a cringe way (:D)
  • Bump statistics, keeps track of how often people bump the server just for fun
  • A bunch of other small fun commands like retrieving info from urban dictionary, generate images with AI and more
  • Moderator statistics to see how productive moderators are

Installing

  1. Download this repo and install al its dependencies with composer install
  2. Create your env file mv .env.example .env and fill in database credentials
  3. Fill in you Discord bot token credentials and any other api credentials:
BOT_TOKEN=
APPLICATION_ID=
SUPPORT_GUILD=
DISCORD_API=

TOPGG_TOKEN=
TOPGG_HOST=
TOPGG_ID=

URB_TOKEN=
URB_HOST=
OPENAI_API_KEY=
OPEN_AI_HOST=

Database

The bot will set up everything correctly when it detects a guild for the first time. However you can use the seeder GuildSeeder and DiscordUsersSeeder to setup any users and guilds manually.

 class DiscordUsersSeeder extends Seeder
{
    public function run()
    {
        $ids = [
            '<discord_owner_id_here>', 
        ];
        foreach ($ids as $id) {
            DiscordUser::factory()->create([
                'discord_id' => $id,
            ]);
        }
    }
}
class GuildSeeder extends Seeder
{
    public function run()
    {
        $guilds = [
            [
                'name' => '<guild_name_here>',
                'guild_id' => '<guild_id_here>', // Servers are guilds
                'owner_id' => 1, // First user added in DiscordUsersSeeder
            ],
        ];
        foreach ($guilds as $guild) {
            Guild::factory()->create($guild);
        }
    }
}
  • If you let the bot detect guilds itself you can set up the database using php artisan migrate:fresh --seeder=PermissionSeeder.
  • To run all seeders including users and guilds you can use php artisan migrate:fresh --seed.

Managing Slash commands

Managing slash commands is done through a separate cmd app using php artisan. When updating and deleting a bunch of commands you will be rate limited. Meaning it takes while before everything is registered. When deleting commands the console output will tell you the progress, however when adding commands the output it only send when everything is done (will change in the future), dont ctrl + c!

  • php artisan bot:slash - Shows current available slash commands in discord! Not your config!
  • php artisan bot:slash --update - Creates/updates all slash commands.
  • php artisan bot:slash --delete - Delete all slash commands.

Running the bot

You can use the following commands to run the bot:

  • php artisan bot:run - Run the bot, does not create, update or delete slash commands!
  • php artisan queue:work - Run de redis queue for reminders.

Configuration

There are three main configuration files for the bot (which you should bother with):

  • config/commands.php - Define all slash commands here and their respective classes
  • config/events.php - Define all event here and their respective classes
  • config/discord.php - Global configuration - actual values should be in your .ENV file.

discord.php

The actual values of these config files should be changed in your local .env. I pasted this config here so you know what all the values mean.

    /*
    |--------------------------------------------------------------------------
    | Bot Token
    |--------------------------------------------------------------------------
    |
    | This is your bot token you can see only once when creating your bot
    | in the discord developers portal. KEEP IT SECRET!
    |
    */

    'token' => env('BOT_TOKEN', ' '),

    /*
    |--------------------------------------------------------------------------
    | Application ID
    |--------------------------------------------------------------------------
    |
    | The application ID is the ID of your bot, it can be found in the dev
    | portal at the top!
    |
    */

    'app-id' => env('APPLICATION_ID', ' '),

    /*
    |--------------------------------------------------------------------------
    | Discord API
    |--------------------------------------------------------------------------
    |
    | We use this API directly to manage our slash commands, instead of doing
    | it through the bot.
    |
    */

    'api' => env('DISCORD_API', 'https://discord.com/api/v10/'),

    /*
    |--------------------------------------------------------------------------
    | Support Guild
    |--------------------------------------------------------------------------
    |
    | ID of your main guild, register any administrative commands there!
    |
    */

    'support-guild' => env('SUPPORT_GUILD', ' '),

    /*
    |--------------------------------------------------------------------------
    | Service Providers
    |--------------------------------------------------------------------------
    |
    | Service providers can be used to "provide a service", basically load
    | and setup some stuff the bot needs. The Event en Command Service
    | Provider are default, I added one for guilds since I need to
    | load all the guilds on boot.
    |
    | Implement the ServiceProvider interface!
    |
    */
    'providers' => [
        EventServiceProvider::class,
        CommandServiceProvider::class,
        GuildServiceProvider::class,
    ],
    
    /*
    |--------------------------------------------------------------------------
    | Top.gg
    |--------------------------------------------------------------------------
    |
    | If you have your bot listed on top.gg you can use their api to update
    | the server count on the website. So people know your bot is being
    | used!
    |
    */

    'topgg-host' => env('TOPGG_HOST', 'https://top.gg/api/'),
    'topgg-id' => env('TOPGG_ID', ' '),
    'topgg-token' => env('TOPGG_TOKEN', ' '),


    /*
    |--------------------------------------------------------------------------
    | Other Settings
    |--------------------------------------------------------------------------
    |
    | My bot uses Urban Dictionary and OpenAI API's for some commands, when
    | you create settings in your bot. Add them to your .env, add them
    | here and use this config to access the values.
    |
    */

    'urb-token' => env('URB_TOKEN', ' '),
    'urb-host' => env('URB_HOST', ' '),
    'open-ai-key' => env('OPENAI_API_KEY', ' '),
    'open-ai-host' => env('OPEN_AI_HOST', ' '),

commands.php

I don't like to autoload my commands. I use the subcommand structure for everything and I want complete freedom to say which command is in which category without being restricted by a certain directory structure, or go into each command class to define the command group there, this gives you a nice overview.

When adding commands to this list you need to either extend the SlashCommand or SlashIndexCommand class. I added the command sub-command structure as described by discord below. Define the array in the same way.

    /*
    |--------------------------------------------------------------------------
    | Slash Command Structure
    |--------------------------------------------------------------------------
    |
    | Here you may specify all your slash commands used by the bot. Remember to
    | add classes which extend the SlashCommand or SlashIndexCommand.
    |
    | 'GLOBAL' AND 'GUILD' ARE NOT PART

Related Skills

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated12mo ago
Forks4

Languages

PHP

Security Score

67/100

Audited on Apr 7, 2025

No findings