Skip to content

how i can pass a variable to an class #688

Closed Answered by Lukasss93
flakka2022 asked this question in Q&A
Discussion options

You must be logged in to vote

Just do this:

<?php

namespace App;

use SergiX44\Nutgram\Nutgram;

require_once '../vendor/autoload.php';

$bot = new Nutgram('YOUR-TOKEN');

$bot->onCommand('start', new StartCommand('my custom data'));

$bot->run();
<?php

namespace App;

use SergiX44\Nutgram\Nutgram;

class StartCommand
{
    public function __construct(protected string $data = '')
    {
    }
    
    public function __invoke(Nutgram $bot): void
    {
        $bot->sendMessage('Hello! My custom data is: ' . $this->data);
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by flakka2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants