{"_id":"576507c14e63520e00a9ff34","user":"571193c63590a50e00bba99d","__v":13,"category":{"_id":"57590727ace5c30e00cb23d8","__v":0,"version":"57590727ace5c30e00cb23d7","project":"571193ce8103870e00f48b67","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-04-16T01:22:22.642Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"version":{"_id":"57590727ace5c30e00cb23d7","__v":2,"project":"571193ce8103870e00f48b67","createdAt":"2016-06-09T06:05:27.924Z","releaseDate":"2016-06-09T06:05:27.924Z","categories":["57590727ace5c30e00cb23d8","57590cd318760817001e8a83"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"4.0.0","version":"4.0.0"},"project":"571193ce8103870e00f48b67","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-18T08:35:13.444Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"Converting from DiscordPHP Version 3 has some major things you need to look out for.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Discord and WebSocket classes\"\n}\n[/block]\nThe Discord and WebSocket classes have been merged into one class.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n// Old version\\n$discord = new Discord('mytoken');\\n$ws = new WebSocket($discord);\\n\\n$ws->on('ready', function ($discord) use ($ws) {\\n    // Update presence\\n  \\t$ws->updatePresence(new Game());\\n});\\n\\n$ws->run();\\n\\n// New version\\n$discord = new Discord([\\n    'token' => 'mytoken',  \\n]);\\n\\n$discord->on('ready', function ($discord) {\\n  \\t// Update presence\\n\\t\\t$discord->updatePresence($discord->factory(Game::class));\\n});\\n\\n$discord->run();\",\n      \"language\": \"php\",\n      \"name\": \"Discord Class\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Options Array\"\n}\n[/block]\nThe Symfony OptionsResolver has been implemented. See all the new options available [here](doc:options).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Promises\"\n}\n[/block]\nFunctions that send HTTP requests (along with other functions where applicable) now return Promises. Read up on the JavaScript version of Promises [here](https://promisesaplus.com/).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$guild = $discord->guilds->first();\\n$channel = $guild->channels->getAll('type', 'text')->first();\\n\\n// Old version\\n$message = $channel->sendMessage('we sync now');\\necho \\\"The message was sent!\\\\r\\\\n\\\";\\n\\n// New version\\n$channel->sendMessage('we async now')->then(function ($message) {\\n    echo \\\"The message was sent!\\\\r\\\\n\\\";\\n})->otherwise(function ($e) {\\n    echo \\\"There was an error sending the message: {$e->getMessage()}\\\\r\\\\n\\\";\\n});\",\n      \"language\": \"php\",\n      \"name\": \"Promise Example\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Part Factories\"\n}\n[/block]\nYou can no longer create parts by just running `new Part()` as the HTTP client is no longer static.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n// Old version\\n$channel = new Channel(['name' => 'mynewchannel', 'type' => 'text']);\\n\\n// New version\\n$channel = $discord->factory(Channel::class, ['name' => 'mynewchannel', 'type' => 'text']);\",\n      \"language\": \"php\",\n      \"name\": \"Model Creation\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Updating and Deleting Parts\"\n}\n[/block]\nThe `save()` and `delete()` methods have been removed from the Part object and have been introduced into [Repositories](doc:repository) in an effort to move away from the Active Record pattern.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$guild = $discord->guilds->first();\\n$channel = $discord->factory(Channel::class);\\n\\n$channel->name = 'mynewchannel';\\n$channel->type = 'text';\\n\\n// Old version:\\n$channel->save();\\n\\n// New version:\\n$guild->channels->save($channel)->then(function ($channel) use ($guild) {\\n    echo \\\"Created channel {$channel->name}\\\\r\\\\n\\\";\\n  \\n  \\t// Old version:\\n    $channel->delete();\\n  \\n  \\t// New version:\\n    $guild->channels->delete($channel)->then(function ($channel) {\\n        echo \\\"Deleted channel {$channel->name}\\\\r\\\\n\\\";\\n    });\\n});\",\n      \"language\": \"php\",\n      \"name\": \"Repository\"\n    }\n  ]\n}\n[/block]","excerpt":"Provides information on converting from DiscordPHP Version 3.x","slug":"converting-from-version-3x","type":"basic","title":"Converting from Version 3.x"}

Converting from Version 3.x

Provides information on converting from DiscordPHP Version 3.x

Converting from DiscordPHP Version 3 has some major things you need to look out for. [block:api-header] { "type": "basic", "title": "Discord and WebSocket classes" } [/block] The Discord and WebSocket classes have been merged into one class. [block:code] { "codes": [ { "code": "<?php\n\n// Old version\n$discord = new Discord('mytoken');\n$ws = new WebSocket($discord);\n\n$ws->on('ready', function ($discord) use ($ws) {\n // Update presence\n \t$ws->updatePresence(new Game());\n});\n\n$ws->run();\n\n// New version\n$discord = new Discord([\n 'token' => 'mytoken', \n]);\n\n$discord->on('ready', function ($discord) {\n \t// Update presence\n\t\t$discord->updatePresence($discord->factory(Game::class));\n});\n\n$discord->run();", "language": "php", "name": "Discord Class" } ] } [/block] [block:api-header] { "type": "basic", "title": "Options Array" } [/block] The Symfony OptionsResolver has been implemented. See all the new options available [here](doc:options). [block:api-header] { "type": "basic", "title": "Promises" } [/block] Functions that send HTTP requests (along with other functions where applicable) now return Promises. Read up on the JavaScript version of Promises [here](https://promisesaplus.com/). [block:code] { "codes": [ { "code": "<?php\n\n$guild = $discord->guilds->first();\n$channel = $guild->channels->getAll('type', 'text')->first();\n\n// Old version\n$message = $channel->sendMessage('we sync now');\necho \"The message was sent!\\r\\n\";\n\n// New version\n$channel->sendMessage('we async now')->then(function ($message) {\n echo \"The message was sent!\\r\\n\";\n})->otherwise(function ($e) {\n echo \"There was an error sending the message: {$e->getMessage()}\\r\\n\";\n});", "language": "php", "name": "Promise Example" } ] } [/block] [block:api-header] { "type": "basic", "title": "Part Factories" } [/block] You can no longer create parts by just running `new Part()` as the HTTP client is no longer static. [block:code] { "codes": [ { "code": "<?php\n\n// Old version\n$channel = new Channel(['name' => 'mynewchannel', 'type' => 'text']);\n\n// New version\n$channel = $discord->factory(Channel::class, ['name' => 'mynewchannel', 'type' => 'text']);", "language": "php", "name": "Model Creation" } ] } [/block] [block:api-header] { "type": "basic", "title": "Updating and Deleting Parts" } [/block] The `save()` and `delete()` methods have been removed from the Part object and have been introduced into [Repositories](doc:repository) in an effort to move away from the Active Record pattern. [block:code] { "codes": [ { "code": "<?php\n\n$guild = $discord->guilds->first();\n$channel = $discord->factory(Channel::class);\n\n$channel->name = 'mynewchannel';\n$channel->type = 'text';\n\n// Old version:\n$channel->save();\n\n// New version:\n$guild->channels->save($channel)->then(function ($channel) use ($guild) {\n echo \"Created channel {$channel->name}\\r\\n\";\n \n \t// Old version:\n $channel->delete();\n \n \t// New version:\n $guild->channels->delete($channel)->then(function ($channel) {\n echo \"Deleted channel {$channel->name}\\r\\n\";\n });\n});", "language": "php", "name": "Repository" } ] } [/block]