rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

/command@bot doesn't work #715

Closed avannus closed 4 years ago

avannus commented 4 years ago

The bot doesn't recognize /roll@bot commands but does resolve /roll commands

public Ability roll() {
        return Ability
                .builder()
                .name("roll")
                .info("/roll xdy, rolls qty(x) of y-sided dice")
                .locality(ALL)
                .privacy(PUBLIC)
                .action(ctx -> silent.send(Student.rollDice(ctx), ctx.chatId()))
                .build();
    }

I have added a print statement before the return line and it doesn't print even though the bot sees it as a command (The bot is running in privacy mode and the message is definitely considered)

From the console log:

entities=[MessageEntity{type='bot_command', offset=0, length=15, url=null, user=null}]

I can't create a method with .name("roll@bot") because the @ isn't alphanumeric (nor is the bot name)

Is there a way to fix this?

ds64 commented 4 years ago

Do you extend your bot from TelegramLongPollingCommandBot? Maybe related to the issue that I created, https://github.com/rubenlagus/TelegramBots/issues/716. But for me, even normal command don't work at all.

avannus commented 4 years ago

No, my bot extends the AbilityBot (AbsSender -> DefaultAbsSender -> BaseAbilityBot -> AbilityBot -> MyBot). Normal commands work for me (as long as the bot receives them obviously)

addo47 commented 4 years ago

Hey @avannus,

Thanks for using AbilityBot! I'll be here to help you. Have you properly passed in the botUsername in the constructor? That's what's used when commands are getting matched.

Also, adding a print statement behind the return won't be printed on ability execution. Abilities are fetched once and used later on. If you'd like anything to be printed, it must be in the .action or .post methods.

avannus commented 4 years ago

Seems like that was the issue @addo37! I have the bot name as its variable display name, not the actual username. When I DM the bot with /roll@BotDisplayName, it responds (unlike /roll@BotUserName). Should be an easy fix when I get home.

Also, good to know about the Abilities.

Thanks!