{"id":18463719,"url":"https://github.com/commandstring/discordphp-bot-template","last_synced_at":"2025-09-11T23:22:55.523Z","repository":{"id":65324575,"uuid":"550821318","full_name":"CommandString/DiscordPHP-Bot-Template","owner":"CommandString","description":"An unofficial way to structure a discordPHP bot.","archived":false,"fork":false,"pushed_at":"2024-01-22T11:30:28.000Z","size":184,"stargazers_count":13,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T08:51:11.471Z","etag":null,"topics":["discord","discord-bot","discordphp","php","template"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CommandString.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-13T11:36:55.000Z","updated_at":"2024-02-07T23:10:51.000Z","dependencies_parsed_at":"2023-02-14T15:00:47.045Z","dependency_job_id":null,"html_url":"https://github.com/CommandString/DiscordPHP-Bot-Template","commit_stats":null,"previous_names":[],"tags_count":21,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FDiscordPHP-Bot-Template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FDiscordPHP-Bot-Template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FDiscordPHP-Bot-Template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FDiscordPHP-Bot-Template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CommandString","download_url":"https://codeload.github.com/CommandString/DiscordPHP-Bot-Template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796336,"owners_count":20997553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-bot","discordphp","php","template"],"created_at":"2024-11-06T09:07:47.278Z","updated_at":"2025-04-08T07:32:46.034Z","avatar_url":"https://github.com/CommandString.png","language":"PHP","readme":"# DiscordPHP Bot Template\n\nAn unofficial way to structure a discordPHP bot.\n\n# Table of Contents\n\n* [Installation](#installation)\n* [Important Resources](#important-resources)\n* [Configuration](#configuration)\n* [Slash Commands](#slash-commands)\n* [Events](#events)\n* [Disabling Commands and Events](#disabling-commands-and-events)\n* [Extending The Template](#extending-the-template)\n  * [Bootstrap Sequence](#bootstrap-sequence)\n  * [Environment Variables](#environment-variables)\n\n# Installation\n\n```\ncomposer create-project commandstring/dphp-bot\n```\n\n# Important Resources #\n\n[DiscordPHP Class Reference](https://discord-php.github.io/DiscordPHP/guide/)\n\n[DiscordPHP Documentation](https://discord-php.github.io/DiscordPHP/)\n\n[DiscordPHP Discord Server](https://discord.gg/kM7wrJUYU9)\n*Only ask questions relevant to DiscordPHP's own wrapper, not on how to use this.*\n\n[Developer Hub](https://discord.gg/TgrcSkuDtQ) *Issues about this template can be asked here*\n\n# Configuration\n\nCopy the `.env.example` file to `.env` and add your bot token.\n\n# Slash Commands\n\nCreate a class that implements `Core\\Commands\\CommandHandler` and attach the `Core\\Commands\\Command` attribute to it.\n\n```php\n\u003c?php\n\nnamespace Commands;\n\nuse Core\\Commands\\Command;\nuse Core\\Commands\\CommandHandler;\nuse Discord\\Builders\\CommandBuilder;\nuse Discord\\Parts\\Interactions\\Interaction;\n\nuse function Core\\messageWithContent;\n\n#[Command]\nclass Ping implements CommandHandler\n{\n    public function handle(Interaction $interaction): void\n    {\n        $interaction-\u003erespondWithMessage(messageWithContent('Ping :ping_pong:'), true);\n    }\n\n    public function autocomplete(Interaction $interaction): void\n    {\n    }\n\n    public function getConfig(): CommandBuilder\n    {\n        return (new CommandBuilder())\n            -\u003esetName('ping')\n            -\u003esetDescription('Ping the bot');\n    }\n}\n```\n\nOnce you start the bot, it will automatically register the command with Discord.\nAnd if you make any changes to the config, it will update the command on the fly.\n\n# Events\n\nCreate a class that implements any of the interfaces found inside of `Core\\Events`.\nImplement the interface that matches your desired event.\n\n```php\n\u003c?php\n\nnamespace Events;\n\nuse Core\\Events\\Init;\nuse Discord\\Discord;\n\nclass Ready implements Init\n{\n    public function handle(Discord $discord): void\n    {\n        echo \"Bot is ready!\\n\";\n    }\n}\n```\n\nIf the interface doesn't exist use the [Class Reference](https://discord-php.github.io/DiscordPHP/guide/events/index.html). Just create a interface that has a handle methods with args that match up with the ones in the event. Then sit it inside `/Core/Events`\n\n# Disabling Commands and Events\n\nIf you want to disable a command handler or event listener attach the `Core\\Commands\\Disabled` attribute to it.\n\n```php\n\u003c?php\n\nnamespace Events;\n\nuse Core\\Events\\Init;\nuse Discord\\Discord;\n\n#[Disabled]\nclass Ready implements Init\n{\n    public function handle(Discord $discord): void\n    {\n        echo \"Bot is ready!\\n\";\n    }\n}\n```\n\n# Extending The Template\n\n## Bootstrap Sequence\n\nCreate a file inside `/Bootstrap` and then require it inside of `/Boostrap/Requires.php`.\n\n## Environment Variables\n\nAdd a doc comment to `/Core/Env.php` and then add the variable to `.env`\n\n*You should also add it to `.env.example`*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandstring%2Fdiscordphp-bot-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommandstring%2Fdiscordphp-bot-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandstring%2Fdiscordphp-bot-template/lists"}