我向我的命令添加参数,并try 根据这些参数获得结果,例如
/Query-NAME MARS
当我写这个的时候,我想要根据这里的名字来检测它,我应该怎么做呢?
我向我的命令添加参数,并try 根据这些参数获得结果,例如
/Query-NAME MARS
当我写这个的时候,我想要根据这里的名字来检测它,我应该怎么做呢?
要回答您的问题,您可以使用Telegraf的中间件系统.以下是一个示例代码:
const { Telegraf } = require('telegraf');
const bot = new Telegraf('YOUR_BOT_TOKEN');
bot.command('name', (ctx) => {
const name = ctx.message.text.split(' ')[1];
ctx.reply(`You entered the name: ${name}`);
});
bot.launch();
我希望这能有所帮助!