justdmitry / NetTelegramBotApi

C# client library for building Telegram bot
MIT License
74 stars 28 forks source link

Left from group when add #64

Closed hanigamini closed 6 years ago

hanigamini commented 6 years ago

Hi, How can I Left from group when some one add my bot to group ?

justdmitry commented 6 years ago

I don't see any requests like self-kicking in Telegram bot api. May be https://core.telegram.org/bots/api#kickchatmember may help, but your bot must be admin in chat.

hanigamini commented 6 years ago

I want prevent unwanted add my bot in group , I want left form that group. this is method , leaveChat , how can i use it? https://core.telegram.org/bots/api#leavechat

justdmitry commented 6 years ago

I can't find something in Telegram bot API docs that may help you.

Any bot may be added in any chat. You may start replying on every message in chat with some spam and humans will remove your bot very quickly ;)

hanigamini commented 6 years ago

leaveChat , how can i use it? https://core.telegram.org/bots/api#leavechat

justdmitry commented 6 years ago

Wow, my eyes. You are right, that's exactly what you need.

So, just send 'LeaveChat`:

var chatToLeave = message.Chat.Id;
await bot.SendAsync(chatToLeave, new LeaveChat(chatToLeave));
hanigamini commented 6 years ago

your code not work , whast is the diffrence with this ? bot.MakeRequestAsync(new LeaveChat(chatToLeave)).Wait();

justdmitry commented 6 years ago

Ouch, sorry.

I'm not with VS now, writing in "notepad". My code is from NetTelegramBot.Framework, it will not compile in "naked" NetTelegramBotApi.

Your code is correct one and should work.

hanigamini commented 6 years ago

Thank you very much, I add try cacth in c# because somtime have error with LeaveChat. and bot is in hanging. Is there any way for that ?