0

I got this bot that I made. Every piece of command works just fine after I deployed it via

git push heroku master

Except this piece of code

const Telegraf = require('telegraf');
const Telegram = require('telegraf/telegram')
const bot = new Telegraf('******');

bot.command(['pin', 'Pin', 'PIN'], function(ctx) {
        if (ctx.message.reply_to_message == undefined){
            ctx.reply("Asegurate de responder al mensaje que quieras fijar")
    }

        var chatId = ctx.chat.id;
        var fromId = ctx.from.id;
        var messageId = ctx.message_id;
        var chatype = ctx.chat.type;
        var replyFrom = ctx.message.reply_to_message.message_id;
        var fromName = ctx.from.username;
        
        const opts = {};
        opts.disable_notification = false;
        
        ctx.telegram.getChatMember(chatId, fromId).then(function(data){
            if ((data.status == 'creator') || (data.status == 'administrator')){
                if (chatype == 'supergroup'){
                    ctx.telegram.pinChatMessage(chatId, replyFrom);
                    ctx.deleteMessage();
                }
                else if (chatype == 'private'){
                    ctx.telegram.sendMessage(chatId, "Comando solo disponible en supergrupos");
                }
                else if (chatype == 'group'){
                    ctx.telegram.sendMessage(chatId, "Comando solo disponible en supergrupos.");
                }
            }
            else {
                ctx.telegram.sendMessage(chatId, "Lo siento " + fromName + " no eres administrador");
            }
        })
});

I have no clue what's causing this problem. The terminal shows no errors and it only works once I bot.launch() it. I have tried re-writting it from scratch, made it differently but nothing works. Every piece of advise and/or comments are helpful. Thanks in advance.

Shork
  • 3
  • 3
  • This might help https://stackoverflow.com/questions/5338551/how-does-git-push-heroku-master-know-where-to-push-to-and-how-to-push-to-a-dif – react_or_angluar Dec 17 '20 at 01:36
  • Eehh.. I don't really get it. I know it's deploying right because all the new stuff I add works but that bot.command. – Shork Dec 17 '20 at 03:19
  • What does it mean to bot.launch() it?Any of these links helpful? https://stackoverflow.com/questions/61692630/heroku-discord-bot-builds-but-doesnt-work https://devcenter.heroku.com/articles/procfile or https://stackoverflow.com/questions/63245834/heroku-discord-bot-builds-but-doesnt-work-when-deployed – react_or_angluar Dec 17 '20 at 03:22
  • bot.launch() is what you use to launch the bot on the spot (along with nodemon) and test it. Thank you for the links. I'm trying their solutions now. – Shork Dec 17 '20 at 04:05
  • Feel free to ignore me, I know almost nothing about this topic. – react_or_angluar Dec 17 '20 at 04:06
  • now it throws me this error: `2020-12-17T04:10:27.744555+00:00 app[web.1]: Launch failed 2020-12-17T04:10:27.746300+00:00 app[web.1]: Error: 401: Unauthorized 2020-12-17T04:10:27.746301+00:00 app[web.1]: at /app/node_modules/telegraf/core/network/client.js:281:17 2020-12-17T04:10:27.746311+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:93:5) 2020-12-17T04:10:27.746788+00:00 app[web.1]: μ-bot: Bot started` – Shork Dec 17 '20 at 04:13

0 Answers0