Closed mafia-007 closed 7 years ago
@mafia-007 lib is not updated yet. So you can't use deleteMessage
method. Wait an update :)
This was added in cda9d8d. I think this issue can be closed now.
How delete all messages in the group? Or limit == 100 messages ? Please A example you mention. Thanks
You cannot delete all messages, only the ones sent since the bot was added, maybe unless you manually tell the bot to delete each message before that separately, but then it's not any faster than deleting them manually yourself. Bots don't get the history of messages sent before they are first added, not even in supergroups. Why don't you just delete and re-create the group?
Here's an example to remove 100 message in the group
By loop
@mafia-007:
From our test suite (test/telegram.js#L891):
it('should delete message', function test() {
return bot.deleteMessage(USERID, messageId).then(resp => {
assert.equal(resp, true);
});
});
API Reference: TelegramBot#deleteMessage().
@telegram-api: you could follow https://github.com/GochoMugo/tgfancy/issues/13.
@nyuszika7h Thanks for the help handling this issue. :+1: :+1: :+1:
@Lord-Protector We going to release it soon. Please hold on. :wink:
Hello @GochoMugo Please send an example with this method
bot.deleteMessages(chatID, [msgID1, msgID2, msgID3, / ... msgIDN /]);
Help me
@telegram-api
const arrayOfMessages = [msgID1, msgID2, msgID3, /* ... msgIDN */];
for (let i in arrayOfMessages) {
await bot.deleteMessage(msg.chat.id, arrayOfMessages[i]);
}
But of course this construction should be in async
function. And yes, you can just remove await
word, but then if you will delete many messages (30+) Telegram will just ban you because of spaming. So you should do synchronous cycle to avoid via async/await it or anti-patterns with promises.
Also you can modify it and by using Promise.all
resolve groups with for example 10 deleteMessage-promises and then do it with something like setInterval
to speed up synchronous cycle and avoid bans from Bot API.
bot.onText(/^[\/!#]del$/, msg => {
var arrayOfMessages = [msg.message_id1, msg.message_id2, msg.message_id3, / ... msg.message_idN /];
for (let i in arrayOfMessages) { bot.deleteMessage(msg.chat.id, arrayOfMessages[i]); } });
Is true?
@telegram-api as I said with many messages telegram will ban you. This code is better, but requires Node.js 7+.
bot.onText(/^[/!#]del$/, async function (msg) {
const arrayOfMessages = [msgID1, msgID2, msgID3, /* ... msgIDN */];
for (let i in arrayOfMessages) {
await bot.deleteMessage(msg.chat.id, arrayOfMessages[i]);
}
});
@Lord-Protector http://uupload.ir/files/9f9e_ftrt.jpg
@telegram-api you should specify msg ids that you give in array. For example:
let arrayOfMessages = [];
for (let i = 0; i < 100; i++) {
arrayOfMessages.push(msg.message_id - i);
}
Any news on this?
@riseremi use master-branch. I don't know why they don't update npm yet. I already switched on Telegraf.js
lib -__-
@Lord-Protector oh thank you!
Sorry guys, we have been unavailable for some time now. We shall push a new release to npm this week. Will close this issue as soon as we do so. Sorry for the wait.
New Release, v0.28.0 :confetti_ball:
Nice, thank you!
We suffer from this problem a lot. We kindly ask you to publish a code against banning Telegram so that we can fix the problems of our bots
hi How Reply a message is deleted? If the code is correct? What code is deleted with group messaging? If the code is correct?
bot.onText(/^[/!#]delete$/, msg => {
bot.deleteMessage(msg.chat.id, msg.reply_to_message.id, form = {}); });
please guide me
in place of msg.reply_to_message.id use msg.reply_to_message.message_id
hi How Reply a message is deleted? If the code is correct? What code is deleted with group messaging? If the code is correct?
bot.onText(/^[/!#]delete$/, msg => {
bot.deleteMessage(msg.chat.id, msg.reply_to_message.id, form = {}); });
please guide me