Code Monkey home page Code Monkey logo

Comments (3)

RealPeha avatar RealPeha commented on May 24, 2024

you need to send different buttons for admin and for users
for example:

if (admin) {
   ctx.reply('you are admin', Keyboard.reply(['Admin button']))
} else {
   ctx.reply('you are user', Keyboard.reply(['User button']))
}

from telegram-keyboard.

 avatar commented on May 24, 2024

Thank you, I tried it and i still the following issue:

  • The bot will show the buttons to all users regardless of if they are admin or not
  • The non admin users can click the buttons and the reply is given in the chat but no bot action is taken, it's ignored
  • If the admin selects any buttons the non admins can see the button menu change in realtime too

How do I stop non admins from seeing the menu at all? or limiting it to the current user interacting with it only?

Here's my code:

const main = (ctx) => {
    if( ctx.from._is_in_admin_list ){
    return ctx.reply('Select your audio list', Keyboard.reply(['Controls'], { columns: 1 }))
}
else {
}
}
bot.use(function(ctx, next){
	if( ctx.chat.id > 0 ) return next();
		return bot.telegram.getChatAdministrators(ctx.chat.id)
		.then(function(data){
			if( !data || !data.length ) return;
			console.log('admin list:', data);
			ctx.chat._admins = data;
			ctx.from._is_in_admin_list = data.some( adm => adm.user.id === ctx.from.id );
		})
		.catch(console.log)
		.then(_ => next(ctx));
});

bot.start(main)
bot.hears('Back', main)
bot.hears('Controls', (ctx) => {
    if( ctx.from._is_in_admin_list ){
    const keyboard = Keyboard.make(["/stop","/pause","/resume","/skip"], { columns: 2 })
    return ctx.reply('Controls menu selected', Keyboard.combine(keyboard, backKeyboard).reply())
}
else {
//do nothing
}
})

bot.launch()

from telegram-keyboard.

RealPeha avatar RealPeha commented on May 24, 2024

I understand your bot works in groups. Well, in that case it seems to me that you cannot separate the buttons for the admin and for the users. But I'm not really very familiar with this, so I can't say for sure.

from telegram-keyboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.