There is a way to separate commands over multiple classes?
See original GitHub issueHi,
I have created a Middleware
called Menu
which contains the following code:
`const TelegrafInlineMenu = require(‘telegraf-inline-menu’); const { BillingCommand } = require(‘./commands/billing’);
class Menu {
constructor(bot) {
const menu = new TelegrafInlineMenu(ctx => `Hey ${ctx.from.first_name}!`);
menu.setCommand('start');
menu.use(new BillingCommand(menu)); // ? how to import other command?
menu.simpleButton('Come Funziona', 'b', {
doFunc: ctx => ctx.reply('As am I!')
});
bot.use(menu.init());
}
}
exports.Menu = Menu;`
I want organize the menu in different command middleware class, let’s take as example BillingCommand
, how can I bound the BillingCommand to the actual menu? The code above isn’t working 'cause I get:
menu.use is not a function
the billing class contains this:
`const TelegrafInlineMenu = require(‘telegraf-inline-menu’);
class BillingCommand {
constructor(menu){
menu.simpleButton('Crea abbonamento', 'a', {
doFunc: ctx => ctx.reply('As am I!')
});
}
}
exports.BillingCommand = BillingCommand;`
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How can I split my Click commands, each with a set of sub ...
Is it possible to organize commands and their subcommands into separate classes? Here's an example of how I would like to separate it:...
Read more >Bukkit for Beginners - Using Multiple Classes for Commands
Learn how to truly understand Java and Bukkit plugin coding from the beginning. If you're new to Java as well as Bukkit, then...
Read more >Combine and Execute Multiple Linux Commands - Baeldung
In this tutorial, we'll see the different ways in which we can combine and execute multiple Linux commands efficiently.
Read more >How to provide multiple statements on a single line in Python?
These statements can very well be written in one line by putting semicolon in between. a=10; b=20; c=1*b; print (c). A new block...
Read more >Python Statements - Multiline, Simple, and Compound Examples
Python statements are the code instructions that are executed by the Python interpreter. Python executes statements one by one as they appear in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
is the short form of
Using an object rather than a direct export you are able to export multiple things at once. I never do for menus but I try to keep it the same everywhere.
Something like this is quite common for me:
which is also the short for
Personally I prefer TypeScript over JavaScript in this case too. In TypeScript you mark each of the to be exported things at the place where you write them:
Using multiple files should work this way:
events.js
main.js
I hope it helps! 😃