2017-07-07 193 views
1

我正在使用laravel 5.4和Telegram Bot SDKTelegram Bot SDK添加命令

我想添加一個命令到我的機器人。

我嘗試添加StartCommand的​​但我得到錯誤。

Command class "Vendor\App\Commands\StartCommand" not found! 

但文件說:

只要你的命令,可以根據您的composer.json設置

,我存儲StartCommand class自動載入你可以存儲在任意目錄中的自定義命令在app\StartCommand.php

這裏是我composer.json

... 
, 
"autoload": { 
    "classmap": [ 
     "database" 
    ], 
    "psr-4": { 
     "App\\": "app/" 
    } 
}, 
... 

這裏是telegrom-BOT-SDK配置`配置\ telegram.php:

... 
    'commands' => [ 
     Telegram\Bot\Commands\HelpCommand::class, 
     Vendor\App\Commands\StartCommand::class, 
    ], 
]; 

回答

1

我必須用我的文件的當前的命名空間。

如果我存儲命令文件中app\,我應該在我的代碼使用

namespace App; 

,而不是

namespace Vendor\App\Commands; 

config\telegram.php

... 
    'commands' => [ 
     Telegram\Bot\Commands\HelpCommand::class, 
     App\StartCommand::class, 
    ], 
];