{"_id":"57590728ace5c30e00cb23d9","createdAt":"2016-04-16T01:22:22.670Z","title":"Getting Started with DiscordPHP","link_url":"","sync_unique":"","type":"basic","user":"571193c63590a50e00bba99d","hidden":false,"body":"This page will help you with setting up a basic bot in DiscordPHP.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Composer\",\n  \"body\": \"At this stage we assume you have set up [Composer](https://getcomposer.org) and added it to your PATH.\"\n}\n[/block]\nFirst off, you will want to make a new folder and initialise a Composer project.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ mkdir MyNewBot && cd MyNewBot\\n$ composer init\\n  Welcome to the Composer config generator\\n\\nThis command will guide you through creating your composer.json config.\\n\\nPackage name (<vendor>/<name>) [david/my-new-bot]: david/awesome-bot\\nDescription []: This is my new bot!\\nAuthor [David Cole <david:::at:::team-reflex.com>, n to skip]: <enter>\\nMinimum Stability []: <enter>\\nPackage Type []: <enter>\\nLicense []: <enter>\\n\\nDefine your dependencies.\\n\\nWould you like to define your dependencies (require) interactively [yes]? <enter>\\nSearch for a package: <enter>\\nWould you like to define your dev dependencies (require-dev) interactively [yes]? <enter>\\nSearch for a package: <enter>\\n\\n{\\n    \\\"name\\\": \\\"david/awesome-bot\\\",\\n    \\\"description\\\": \\\"This is my new bot!\\\",\\n    \\\"authors\\\": [\\n        {\\n            \\\"name\\\": \\\"David Cole\\\",\\n            \\\"email\\\": \\\"david@team-reflex.com\\\"\\n        }\\n    ],\\n    \\\"require\\\": {}\\n}\\n\\nDo you confirm generation [yes]? <enter>\",\n      \"language\": \"text\",\n      \"name\": \"Composer Init\"\n    }\n  ]\n}\n[/block]\nWe will now require DiscordPHP into your Composer project.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ composer require team-reflex/discord-php\",\n      \"language\": \"text\",\n      \"name\": \"Composer Require\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"DiscordPHP Version\",\n  \"body\": \"This command will install the latest release of DiscordPHP. If you want to test out the `master` or `develop` branches, add either `dev-master` or `dev-develop` as a suffix to the end of the command.\"\n}\n[/block]\nYou will now want to create a file called `run.php` in the directory you created before. This will be the file that you run to start your bot.\n\nOpen the file you just created in your favourite text editor (Sublime Text is best) and add this code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\ninclude __DIR__.'/vendor/autoload.php';\\n\\n$discord = new \\\\Discord\\\\Discord([\\n\\t\\t'token' => 'your-auth-token',\\n]);\\n\\n$discord->on('ready', function ($discord) {\\n\\t\\techo \\\"Bot is ready.\\\", PHP_EOL;\\n  \\n \\t\\t// Listen for events here\\n  \\t$discord->on('message', function ($message) {\\n      \\techo \\\"Recieved a message from {$message->author->username}: {$message->content}\\\", PHP_EOL;\\n    });\\n});\\n\\n$discord->run();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nYou can now start your program by typing the following into your terminal.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ php run.php\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nYou can now modify this basic code with more features that you can find out about in these docs.","category":"57590727ace5c30e00cb23d8","isReference":false,"link_external":false,"order":0,"project":"571193ce8103870e00f48b67","slug":"getting-started","api":{"settings":"","url":"","auth":"required","params":[],"results":{"codes":[]}},"version":"57590727ace5c30e00cb23d7","excerpt":"This page will help you with setting up a basic bot in DiscordPHP.","githubsync":"","updates":[],"__v":7,"childrenPages":[]}

Getting Started with DiscordPHP

This page will help you with setting up a basic bot in DiscordPHP.

This page will help you with setting up a basic bot in DiscordPHP. [block:callout] { "type": "warning", "title": "Composer", "body": "At this stage we assume you have set up [Composer](https://getcomposer.org) and added it to your PATH." } [/block] First off, you will want to make a new folder and initialise a Composer project. [block:code] { "codes": [ { "code": "$ mkdir MyNewBot && cd MyNewBot\n$ composer init\n Welcome to the Composer config generator\n\nThis command will guide you through creating your composer.json config.\n\nPackage name (<vendor>/<name>) [david/my-new-bot]: david/awesome-bot\nDescription []: This is my new bot!\nAuthor [David Cole <david@team-reflex.com>, n to skip]: <enter>\nMinimum Stability []: <enter>\nPackage Type []: <enter>\nLicense []: <enter>\n\nDefine your dependencies.\n\nWould you like to define your dependencies (require) interactively [yes]? <enter>\nSearch for a package: <enter>\nWould you like to define your dev dependencies (require-dev) interactively [yes]? <enter>\nSearch for a package: <enter>\n\n{\n \"name\": \"david/awesome-bot\",\n \"description\": \"This is my new bot!\",\n \"authors\": [\n {\n \"name\": \"David Cole\",\n \"email\": \"david@team-reflex.com\"\n }\n ],\n \"require\": {}\n}\n\nDo you confirm generation [yes]? <enter>", "language": "text", "name": "Composer Init" } ] } [/block] We will now require DiscordPHP into your Composer project. [block:code] { "codes": [ { "code": "$ composer require team-reflex/discord-php", "language": "text", "name": "Composer Require" } ] } [/block] [block:callout] { "type": "warning", "title": "DiscordPHP Version", "body": "This command will install the latest release of DiscordPHP. If you want to test out the `master` or `develop` branches, add either `dev-master` or `dev-develop` as a suffix to the end of the command." } [/block] You will now want to create a file called `run.php` in the directory you created before. This will be the file that you run to start your bot. Open the file you just created in your favourite text editor (Sublime Text is best) and add this code. [block:code] { "codes": [ { "code": "<?php\n\ninclude __DIR__.'/vendor/autoload.php';\n\n$discord = new \\Discord\\Discord([\n\t\t'token' => 'your-auth-token',\n]);\n\n$discord->on('ready', function ($discord) {\n\t\techo \"Bot is ready.\", PHP_EOL;\n \n \t\t// Listen for events here\n \t$discord->on('message', function ($message) {\n \techo \"Recieved a message from {$message->author->username}: {$message->content}\", PHP_EOL;\n });\n});\n\n$discord->run();", "language": "php" } ] } [/block] You can now start your program by typing the following into your terminal. [block:code] { "codes": [ { "code": "$ php run.php", "language": "text" } ] } [/block] You can now modify this basic code with more features that you can find out about in these docs.