Giter VIP home page Giter VIP logo

discordphp's Introduction

DiscordPHP

Latest Stable Version Latest Unstable Version Total Downloads PHP Version Require

PHP Discorders

A wrapper for the official Discord REST, gateway and voice APIs. Documentation is available here, albeit limited at the moment, as well as a class reference. Feel free to ask questions in the Discord server above.

For testing and stability it would be greatly appreciated if you were able to add our test bot to your server. We don't store any data - the bot simply idles and does not interact with anyone and is used to test stability with large numbers of guilds. You can invite the bot here.

Cache Interface (experimental)

Warning This branch contains an experimental feature, do not use it in production! See the wiki page for more information on how to set it up.

FAQ

  1. Can I run DiscordPHP on a webserver (e.g. Apache, nginx)?
    • No, DiscordPHP will only run in CLI. If you want to have an interface for your bot you can integrate react/http with your bot and run it through CLI.
  2. PHP is running out of memory?
    • Try unlimit your PHP memory using ini_set('memory_limit', '-1');.

Getting Started

Before you start using this Library, you need to know how PHP works, you need to know how Event Loops and Promises work. This is a fundamental requirement before you start. Without this knowledge, you will only suffer.

Requirements

Recommended Extensions

  • One of ext-uv (recommended), ext-ev or ext-event for a faster, and more performant event loop.
  • ext-mbstring if handling non-latin characters.

Voice Requirements

Windows and SSL

Unfortunately PHP on Windows does not have access to the Windows Certificate Store. This is an issue because TLS gets used and as such certificate verification gets applied (turning this off is not an option).

You will notice this issue by your script exiting immediately after one loop turn without any errors.

As such users of this library need to download a Certificate Authority extract from the cURL website.
The path to the caextract must be set in the php.ini for openssl.cafile.

Installing DiscordPHP

DiscordPHP is installed using Composer.

  1. Run composer require team-reflex/discord-php. This will install the latest stable release.
    • If you would like, you can also install the development branch by running composer require team-reflex/discord-php dev-master.
  2. Include the Composer autoload file at the top of your main file:
    • include __DIR__.'/vendor/autoload.php';
  3. Make a bot!

Basic Example

<?php

include __DIR__.'/vendor/autoload.php';

use Discord\Discord;
use Discord\Parts\Channel\Message;
use Discord\WebSockets\Intents;
use Discord\WebSockets\Event;

$discord = new Discord([
    'token' => 'bot-token',
    'intents' => Intents::getDefaultIntents()
//      | Intents::MESSAGE_CONTENT, // Note: MESSAGE_CONTENT is privileged, see https://dis.gd/mcfaq
]);

$discord->on('ready', function (Discord $discord) {
    echo "Bot is ready!", PHP_EOL;

    // Listen for messages.
    $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
        echo "{$message->author->username}: {$message->content}", PHP_EOL;
        // Note: MESSAGE_CONTENT intent must be enabled to get the content if the bot is not mentioned/DMed.
    });
});

$discord->run();

See examples folder for more.

Documentation

Documentation for the latest version can be found here. Community contributed tutorials can be found on the wiki.

Contributing

We are open to contributions. However, please make sure you follow our coding standards (PSR-4 autoloading and custom styling). Please run php-cs-fixer before opening a pull request by running composer run-script cs.

License

MIT License, © David Cole and other contributers 2016-present.

discordphp's People

Contributors

b3r3nd avatar commandstring avatar cryptiklemur avatar davidcole1340 avatar dependabot[bot] avatar dynamogeek avatar exanlv avatar finalgamer avatar hemberger avatar iggyvolz avatar ixiter avatar jaxkdev avatar jocafamaka avatar key2peace avatar kylekatarnls avatar max2408 avatar miomit avatar mohsinengineer avatar mvaessen avatar nerahikada avatar oliverschloebe avatar peanutnl avatar rachids avatar ravisdo avatar refaltor77 avatar shehi avatar slushpuppy avatar sqko avatar valzargaming avatar xwildfire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discordphp's Issues

Example from wiki doesn't work

$discord = new Discord('email', 'pass');
$websocket = new WebSocket($discord);

$discord->findGuild('id of guild');

Gives the error

ErrorException in Discord.php line 157:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Discord\Parts\User\Client' does not have a method 'findGuild'

[bot-api] Reply doesn't seems to work

Here's an error i get by using basic.php

Fatal error: Uncaught exception 'Discord\Exceptions\Rest\NotFoundException' with message 'Error code 404: This resource does not exist. NOT FOUND - {"message": ""} - channels/1.3916996587697E+17/messages' in \src\Discord\Helpers\Guzzle.php:191
Stack trace:
#0 src\Discord\Helpers\Guzzle.php(125): Discord\Helpers\Guzzle::handleError(404, 'NOT FOUND', Object(GuzzleHttp\Psr7\Stream), 'channels/1.3916...')
#1 src\Discord\Helpers\Guzzle.php(61): Discord\Helpers\Guzzle::runRequest('post', 'channels/1.3916...', Array, false, Array)
#2 src\Discord\Parts\Channel\Channel.php(303): Discord\Helpers\Guzzle::__callStatic('post', Array)
#3 src\Discord\Parts\Channel\Channel.php(303): Discord\Helpers\Guzzle::post('channels/1.3916...', Array)

Wiki

It's mentioned "more info on the wiki" but where is the wiki ?

Associate User to Role

Is there a way to associate a Guild Member to a Role within the guild? I'm having significant issues trying to determine whether or not a specific user is in one or more roles.

I am starting with a Discord\Parts\Channel\Message and an array of pre-existing Role names. I'm finding that $message->fullChannel->guild does not have a ->members property, and $message->author does not seem to have any sort of guild/role association.

Thanks!

Some mp3's crash DCA it seems..

Stack trace:
#0 [internal function]: Discord\Voice\VoiceClient->Discord\Voice{closure}(Resource id #1922, Object(React\EventLoop\StreamSelectLoop))
#1 /storage/dev/Sovereign/vendor/react/event-loop/src/StreamSelectLoop.php(232): call_user_func(Object(Closure), Resource id #1922, Object(React\EventLoop\StreamSelectLoop))
#2 /storage/dev/Sovereign/vendor/react/event-loop/src/StreamSelectLoop.php(201): React\EventLoop\StreamSelectLoop->waitForStreamActivity(4576.9214630127)
#3 /storage/dev/Sovereign/vendor/team-reflex/discord-php/src/Discord/WebSockets/WebSocket.php(917): React\EventLoop\StreamSelectLoop->run()
#4 /storage/dev/Sovereign/src/sovereign.php(449): Discord\WebSockets\WebSocket->run()
#5 /storage/dev/Sovereign/Sovereign(60): Sovereign\S in /storage/dev/Sovereign/vendor/team-reflex/discord-php/src/Discord/Voice/VoiceClient.php on line 780```

So yeah, DCA seems to be outdated, maybe an update is in order? :P

Issues with role detection

I noticed this about a week ago just had time to work on this now, but i have a role checking system for Bot Commander and it will no longer detect users in the role.

Thanks Dustin

Possible memory leak

Seems that over time memory usage builds up a lot.

After 2 days my bot was running with around 150-200mb of RAM usage after it started at 25-30mb.

Events mess up collection indexes

When, say MESSAGE_CREATE is recieved, it removes the channel from the Collection and puts it at the end. Easy fix.

$guild->channels->pull($cindex);
$guild->channels->push($channel);

to...

$guild->channels[$cindex] = $channel;

Remove old caching

Need to remove the old caching (attributes_cache) and use the Cache class.

v4 $message->reply no longer working?

Hi. i was using v3, later changed to v4-new because it was a lot more stable, but now i tried the new v4 branch and it seems that $message->reply('pong!'); is no longer working. I never get any message in discord now.

Since that is also not in the example, is it known that it is not working? Has anything changed there or am i just too stupid?

The method at least doesn't seem to have changed.

Implement xsalsa20_poly1305 for voice

Need to look into implementing xsalsa20_poly1305 for encrypted voice. Currently using plain (no encryption).

Will require:

  • libsodium
  • libsodium-php

All are easy to install, shouldn't cause too much hassle.

Composer dependencies not satisfiable

When attempting to run composer require team-reflex/discord-php I receive the following. Ideas?

$ composer require team-reflex/discord-php --verbose

Using version ^3.2 for team-reflex/discord-php
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Dependency resolution completed in 0.001 seconds
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - team-reflex/discord-php v3.2.0 requires trafficcophp/bytebuffer dev-master -> satisfiable by TrafficCophp/ByteBuffer[dev-master] but these conflict with your requirements or minimum-stability
    - team-reflex/discord-php 3.2.1 requires trafficcophp/bytebuffer dev-master -> satisfiable by TrafficCophp/ByteBuffer[dev-master] but these conflict with your requirements or minimum-stability
    - Installation request for team-reflex/discord-php ^3.2 -> satisfiable by team-reflex/discord-php[3.2.1, v3.2.0].


Installation failed, reverting ./composer.json to its original content.

My composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*",
        "doctrine/dbal": "~2.5",
        "cviebrock/eloquent-sluggable": "2.*",
        "ehesp/steam-login": "~1.0.1",
        "team-reflex/discord-php": "^3.2"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    }
}

Can't edit newly created or renamed roles.

Attempted to change role color after role creation.
tried it immediately to no success in finding the role.
Waited about 10-15 minutes and had the same issue..role was null.
About 30-45 minutes or so, the roll was found and edited correctly.
Not sure if this is just discord? but I figured you'd want to know about it.

Also if you edit the role name, it appears to do the same thing.
you have to wait the same amount of time before it's available to edit.

[bot-api] Rest\NoPermissionsException Uncatchable!

I've tried Everything
NoPermissionsException, DiscordRequestFailedException, PartRequestFailedException, \Exceptions, Exceptions.. I even went as far as adding the usefor NoPermissionsException and than repeating all steps above.

Instead of it throwing a DiscordRequestFailedException I've noticed at times It throws the NoPermissions exception..which you can't catch..

Possibly a member chunking issue?

Just updated my composer when i woke up, @uniquoooo I moved all my events into the ready event, without any login errors this time. However this occurs >
untitled

channel_update :: can't edit channel position. changing topic resets the pos.

Everything else changes fine. However on channel edit, you lose your position.
Attempted to store previous pos for the new configuration. Still no success.

$chpos=0;
$guild = $discord->guilds->get('name', $message->full_channel->guild->name);
$channel = $guild->channels->get('id', $message->channel_id);
$chpos=$channel->position;
$name=$channel->name;
// $channel = new \Discord\Parts\Channel\Channel();
// $channel->name = $name;
// $channel->type = $sp[1];   // i have enabled all of these in hopes it would work. 
// $channel->guild_id = $g2;
$channel->position = $chpos
$channel->topic = $msg;   
$channel->save();

I've tested using a vardump and it shows the accurate position before hand.

[bot-api] Bot throws an error when channel is innactive for more than 30 mins.

Here's the error:

Fatal error: Uncaught Error: Call to a member function get() on null in init.php:33
Stack trace:
#0 [internal function]: {closure}(Object(Discord\Parts\Channel\Message), Object(Discord\Discord), Object(Discord\Discord))
#1 /{DISCORD_DIR}/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(64): call_user_func_array(Object(Closure), Array)
#2 /{DISCORD_DIR}/src/Discord/WebSockets/WebSocket.php(633): Evenement\EventEmitter->emit('MESSAGE_CREATE', Array)
#3 /{DISCORD_DIR}/src/Discord/WebSockets/WebSocket.php(249): Discord\WebSockets\WebSocket->handleHandler(Array, Object(stdClass))
#4 [internal function]: Discord\WebSockets\WebSocket->Discord\WebSockets\{closure}(Object(Ratchet\RFC6455\Messaging\Message), Object(Ratchet\Client\WebSocket))
#5 /{DISCORD_DIR}/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(64): call_user_func_array(Object(Closure), Array)

Line 33 of my code is:

$guild = $discord->guilds->get('id', $message->full_channel->guild->id);
$member = $guild->members->get('id', $message->author->id);

$array['userdata'] = $member->user;

if($member->roles->get('name', 'BOT CONTROLING')) { /* This is line 33 */
    $array['can_control_bot'] = TRUE;
} else {
    $array['can_control_bot'] = FALSE;
}

$message->channel->sendMessage("```".json_encode($array)."```");

Version 4.0.0

This is an issue post to gather all information about Version 4.0.0.

Current changes:

  • New caching system
  • Dependency injection
  • Part factories
  • REST client will be passed around instead of using static methods

[bot-api]Opcode 4006 Invalid Session

websocket has been dropping every 10 minutes.
After about 4-5x of restarting. i'll start getting an Opcode 4006 (Invalid Session)
This is only happening on the bot with 230 servers
The other bot is on about 20 servers. websocket closes about 1 time an hour.
No invalid session on the other bot.

Bot crashes after one reply

PHP Notice:  Indirect modification of overloaded property Discord\Parts\Channel\Channel::$members has no effect in /var/bot/vendor/team-reflex/discord-php/src/Discord/WebSockets/Events/GuildCreate.php on line 88
PHP Notice:  Indirect modification of overloaded property Discord\Parts\Channel\Channel::$members has no effect in /var/bot/vendor/team-reflex/discord-php/src/Discord/WebSockets/Events/GuildCreate.php on line 88
Discord WebSocket is ready!
PHP Notice:  Indirect modification of overloaded property Discord\Parts\Channel\Channel::$messages has no effect in /var/bot/vendor/team-reflex/discord-php/src/Discord/WebSockets/Events/MessageCreate.php on line 43
PHP Fatal error:  Uncaught Error: Call to a member function push() on null in /var/bot/vendor/team-reflex/discord-php/src/Discord/Parts/Channel/Channel.php:412
Stack trace:
#0 /var/bot/vendor/team-reflex/discord-php/src/Discord/Parts/Channel/Message.php(80): Discord\Parts\Channel\Channel->sendMessage('<@1097394306962...')
#1 /var/bot/app/init.php(46): Discord\Parts\Channel\Message->reply('pong!')
#2 [internal function]: {closure}(Object(Discord\Parts\Channel\Message), Object(Discord\Discord), Object(Discord\Discord), Object(Discord\WebSockets\WebSocket))
#3 /var/bot/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(64): call_user_func_array(Object(Closure), Array)
#4 /var/bot/vendor/team-reflex/discord-php/src/Discord/WebSockets/WebSocket.php(777): Evenement\EventEmitter->emit('MESSAGE_CREATE', Array)
#5 /var/bot/vendor/team-reflex/discord-php/src/Discord/WebSockets/WebSocket.php(286): Discord\WebSockets\WebSocket in /var/bot/vendor/team-reflex/discord-php/src/Discord/Parts/Channel/Channel.php on line 412

PHP : PHP 7.0.6-1+donate.sury.org~xenial+1 (cli) ( NTS )
Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial

init.php is almost the same as basic.php from examples

bot answers one time, after that crashes

Possible issue with keepalive

Hi there,

My bot disconnects frequently (+/- every hour) with the message Tried to write to closed stream..

Could it be an issue with the keepalive that the Discord API expects?

api@VCC-API001:~$ vccd
[26-04-2016 22:02:39] Connected to the Discord API.
[26-04-2016 22:53:54] Error: exception 'RuntimeException' with message 'Tried to write to closed stream.' in /var/www/vendor/react/stream/src/Buffer.php:108
Stack trace:
#0 [internal function]: React\Stream\Buffer->handleWrite(Resource id #147, Object(React\EventLoop\StreamSelectLoop))
#1 /var/www/vendor/react/event-loop/src/StreamSelectLoop.php(240): call_user_func(Array, Resource id #147, Object(React\EventLoop\StreamSelectLoop))
#2 /var/www/vendor/react/event-loop/src/StreamSelectLoop.php(201): React\EventLoop\StreamSelectLoop->waitForStreamActivity(4895681.142807)
#3 /var/www/vendor/team-reflex/discord-php/src/Discord/WebSockets/WebSocket.php(916): React\EventLoop\StreamSelectLoop->run()
#4 /var/www/backend/vccd(130): Discord\WebSockets\WebSocket->run()
#5 {main}
api@VCC-API001:~$ 

PS: I am using "team-reflex/discord-php": "dev-develop"

Event GUILD_MEMBER_UPDATE does not return the updated role

$ws->on(Event::GUILD_MEMBER_UPDATE,function($guildmember,$discord){
echo 'Guild member update recognized.'PHP_EOL;
}

recognizes the event, but the roles of the guildmember are not updated, only restarting the bot works to get the new roles of the members.
Looks like public function updateDiscordInstance($data, $discord) does not work properly.

Issue with Server Count and Memory Leak

The server count duplicates after 1 hour of running which also increases memory usage. Which could be a issue for large bots

Library: DiscordPHP v3.2.0-beta
Library Revision: b76c8c6
Library Branch: master
PHP Version: 7.0.5-1~dotdeb+8.1
Uptime: 0 day(s), 0 hour(s), 0 minute(s), 9 second(s)
Memory Usage: 41.94mb
OS Info: Linux uk-01.zigibot.com 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64
Server Count: 107
Joined at: 05/04/2016 01:04:55
Guild Region: US East
Guild Users: 4328
Guild Owner: Voltana#8252

after a hour or so

Library: DiscordPHP v3.2.0-beta
Library Revision: b76c8c6
Library Branch: master
PHP Version: 7.0.5-1~dotdeb+8.1
Uptime: 0 day(s), 1 hour(s), 34 minute(s), 58 second(s)
Memory Usage: 71.3mb
OS Info: Linux uk-01.zigibot.com 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64
Server Count: 220
Joined at: 05/04/2016 01:04:55
Guild Region: US East
Guild Users: 4337
Guild Owner: Voltana#8252`

had this issue on master branch and bot-api branch.

URL Resolving & getMessageHistory

It seems there are a couple issues with the both of them currently.
Both of the errors can be replicated with little modification to basic.php.
Witnessed both of them on Debian (Jessie), PHP 5.6.

URL Resolving.
It seems that if the bot receives an URL without having cached/resolved it, it'll throw a bunch of these:

PHP Notice: Trying to get property of non-object in Discord/Parts/Channel/Message.php on lines 134-137

This seems to be because Event::MESSAGE_CREATE gets called twice, once as the message is received, and once when the URL is resolved; in the case of URL resolving, the $message object is missing several properties.

Testing this is relatively simple. Just give the bot a link that a) the bot's never seen and b) has something to resolve. Example link would be http://imgur.com/

getMessageHistory.
Passing a Discord\Parts\Channel\Message object as before to $channel -> getMessageHistory seems to throw a fatal error.

PHP Fatal error:  Uncaught exception 'Exception' with message 'before must be an instance of Discord\Parts\Channel\Message' in Discord/Parts/Channel/Channel.php:300

Stack trace:
#0 /buttbot/self/commands/mentions.php(25): Discord\Parts\Channel\Channel->getMessageHistory(Array)
#1 /buttbot/self/methods.php(133): {closure}(Array, Object(Discord\Parts\Channel\Message))
#2 /buttbot/self/methods.php(133): Closure->__invoke(Array, Object(Discord\Parts\Channel\Message))
#3 /buttbot/self/bot.php(41): command(Object(Discord\Parts\Channel\Message))
#4 [internal function]: {closure}(Object(Discord\Parts\Channel\Message), Object(Discord\Discord), Object(Discord\Discord), Object(Discord\WebSockets\WebSocket))
#5 /Evenement/EventEmitterTrait.php(65): call_user_func_array(Object(Closure), Array)
#6 /Discord/WebSockets/WebSocket.php(780): Evenement\EventEmitter->emit('MESSAGE_CREATE', Array) in /Discord/Parts/Channel/Channel.php on line 300

Can't say what exactly causes this. It's possible a $message is somehow a different type than fetching the message from $channel->messages.
Possibly a namespace issue.
Can be replicated by trying to retrieve Message History before a recently retrieved message within Event::MESSAGE_CREATE.

[dev-develop]Fatal error: Call to a member function pack()

I had this error in my code.
I checked the source code(WebSockets/WebSocket.php) and note that the variable $useEtf is set true, changing the variable to false the code work

The error:
Fatal error: Call to a member function pack() on null in D:\Kouku\vendor\team-reflex\discord-php\src\Discord\WebSockets WebSocket.php on line 950

PD: Sorry for my bad English

Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem

I'm trying to get the basic example bot working that is shown in the readme.php
But whenever I try to load it I get this error:

Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in C:\Dev_enviorment\wamp64\www\Discord-Bot\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187
Stack trace:
#0 C:\Dev_enviorment\wamp64\www\Discord-Bot\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 C:\Dev_enviorment\wamp64\www\Discord-Bot\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 C:\Dev_enviorment\wamp64\www\Discord-Bot\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 C in C:\Dev_enviorment\wamp64\www\Discord-Bot\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187

this is the code in the php file

<?php

include __DIR__.'/vendor/autoload.php';

$token = 'MY_TOKEN';

use Discord\Discord;
use Discord\WebSockets\WebSocket;

$discord = new Discord($token);
$ws      = new WebSocket($discord);

$ws->on('ready', function ($discord) use ($ws) {
    echo "Bot is ready!".PHP_EOL;

    // We will listen for messages
    $ws->on('message', function ($message, $discord) {
        echo "Message from {$message->author->username}: {$message->content}".PHP_EOL;
    });
});

$ws->run();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.