V
V
Vlad Gapanovich2021-03-13 23:52:14
Java
Vlad Gapanovich, 2021-03-13 23:52:14

How to receive and send a message?

I'm having trouble with one little problem. How can I implement it so that when I write the word "Submit" I have the admins(update);
If I do it through if , then my admins(update) is not executed, and the place of this is executed by member(update)

Message message = update.getMessage();
        this.message = message;

        if (message != null && message.hasText()) {
            switch (message.getText()){
                case "/start":
                    Long chatId = update.getMessage().getChatId();
                    this.chatId = chatId;
                    databaseHandler.recordChatId(chatId);
                    System.out.println("Этап старт");
                    sendMsg(update.getMessage(), "Введите Тэг");
                    break;
                case "/admins":
                    if (update.getMessage().getChatId() == Const.TG_ADMIN_PANEL){
                        sendMsg(update.getMessage(),  "Выполнен вход в админ панель");
                        
                        
                            admins(update);

                        System.out.println(message);

                    } else sendMsg(update.getMessage(), "Вы не админ");

                    break;
                default:
                    member(update);
            }

        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2021-03-14
Hasanly @azerphoenix

Good afternoon!
Firstly, it is better to frame the code with the code tag, and not throw it off as a screen.
admins is not executed, since this branch is not executed, but default is executed instead.
See what comes in message.getText()
Note that you have /start in the first branch, and admins in the second (without the slash). Maybe you're typing admins with a slash, which is why it doesn't match?

A
Alex K, 2021-03-14
@alexk111

The presented code has handlers for messages: `/start`, `/admins` and any other messages. Add a `case "send"` for the "send" message handler.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question