-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctx.setCommands not recognized #62
Comments
What's the error that you're seeing? |
In loggedOutCommands.command method, the ctx object I receive from callback, does not recognize setMyCommands |
You need to include the actual error message in full. Alternatively, consider posting your code. Right now, the only thing you gave away is an image of the code. This means that people would have to type out the entire source code you wrote if they wanted to reproduce the issue. That's tedious. Without reproducing the issue, it's very hard to help. |
|
Great catch, our documentation is wrong: https://grammy.dev/plugins/commands#context-shortcut |
I changed the code as suggested. Issue remains, setMyCommands method is not recognizable on ctx object import { Bot, Context } from "grammy";
// import { Menu } from "@grammyjs/menu";
import { CommandGroup, CommandsFlavor, commands } from "@grammyjs/commands";
// TOKEN
const token = "";
// Use the flavor to create a custom context
type MyContext = CommandsFlavor<Context>;
// Use the new context to instantiate your bot
const bot = new Bot<MyContext>(token);
// Register the context shortcut
bot.use(commands());
const loggedOutCommands = new CommandGroup();
const loggedInCommands = new CommandGroup();
loggedOutCommands.command(
"login",
"Start your session with the bot",
async (ctx) => {
await ctx.setMyCommands(loggedInCommands);
await ctx.reply("Welcome! Session started!");
},
);
loggedInCommands.command(
"logout",
"End your session with the bot",
async (ctx) => {
await ctx.setMyCommands(loggedOutCommands);
await ctx.reply("Goodbye :)");
},
);
bot.use(loggedInCommands);
bot.use(loggedOutCommands);
// By default, users are not logged in,
// so you can set the logged out commands for everyone
await loggedOutCommands.setCommands(bot); |
I don't see the part where you "changed the code as suggested". For the current code shown, the error is completely expected. I get the part of just doing |
Addressed in: |
Thanks for the report @dominicpaul1911! There are several issues going on here, but just to address your final issue, the documentations should have said ![]() Do note that this doesn't actually fully resolve your type issues in your use case, where the commandGroups circular set each other. Check out the following comment for more details. |
@carafelix Currently the type of Let us begin with this example provided by the issue author: ![]() Notice that |
Thanks for pointing it out @KnightNiwrem |
I am a noob to telegram bot development and grammy. I installed all of the necessary packages including Grammy and @grammyjs/commands. But I am running into below error, setMyCommands not found on ctx. Could you please help me.
The text was updated successfully, but these errors were encountered: