Ask Question
Asked
Modified 5 years, 3 months ago
Viewed 1k times
I create a telegram bot using the Python-Telegram-Bot framework and the Re Module. The bot should delete the stickers the members send to the group, that is, when the word is start send to the group, it will delete the bot stickers that are sent after the group start.
My code:
from telegram.ext import Updater, MessageHandler, Filters import re def delete_method(bot, update): mlist=['/start'] for i in mlist: if re.match(i, update, message.text): update.message.delete() def main(): updater = Updater(token='TOKEN') dispatcher = updater.dispatcher dispatcher.add_handler(MessageHandler(Filters.all, delete_method)) updater.start_polling() updater.idle() if __name__ == '__main__': main() # for exit # updater.idle()
But the bot does not work, that is, after sending the word start of the send to the group, it does not delete the stickers that are sent to the group.
The codes do not give any errors.And the group is a super group, and the bot is admin and it has access to messages!
What do you think is the problem ???
2
This line here if re.match(i, update, message.text): is the problem. You are searching for i (which has the value /start) in the update object.
I don't see why this should work.
You need to check if the current message is a sticker. If the message is a sticker, then update.effective_message.sticker will return a value. Otherwise it will return None. So you could check for a sticker with this i guess - i didn't test it:
from telegram.ext import Updater, MessageHandler, Filters def delete_sticker(bot, update): if update.effective_message.sticker: update.message.delete if __name__ == '__main__': updater = Updater(token='TOKEN') dispatcher = updater.dispatcher dispatcher.add_handler(MessageHandler(Filters.all, delete_sticker)) updater.start_polling() updater.idle()
0
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Required, but never shown
Required, but never shown
7 - The telegram bot should delete Sticker, Gif, and Voice that are sent to the group;but do not delete themAsked
Modified 5 years, 4 months ago
Viewed 1k times
I built a telegram bot with a python-telegram-bot module.I added the bot to the group and got the bot in the admin group.The bot should be delete when Sticker, Gif or Voice are sent to the group;But the bot does not delete them.bot code:
from telegram.ext import Updater, MessageHandler, Filters def sticker_method(bot, update): bot.delete_sticker(chat_id = update.message.chat_id, sticker_id = update.sticker.chat_id) bot.delete_gif(chat_id = update.message.chat_id, gif_id = update.gif.chat_id) bot.delete_voice(chat_id = update.message.chat_id, voice_id = update.voice.chat_id) def main(): updater = Updater(token='TOKEN') dispatcher = updater.dispatcher dispatcher.add_handler(MessageHandler(Filters.all, sticker_method)) updater.start_polling() updater.idle() if __name__ == '__main__': main() # for exit # updater.idle()
There is no error during execution;But the bot does nothing!
There are no delete_sticker, delete_gif nor delete_voice methods in this library. What you are looking for is bot.delete_message().
Also you can use some extensive filters, for example Filters.sticker and Filters.voice.
More Info (Edited):
For example you can do (with the usage of Filters.sticker and Message.delete()):
def delete_sticker_callback(bot, update): update.message.delete() def main(): updater = Updater(token='TOKEN') dispatcher = updater.dispatcher dispatcher.add_handler(MessageHandler(Filters.sticker, delete_sticker_callback)) updater.start_polling() updater.idle() if __name__ == '__main__': main()
2
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Required, but never shown
Required, but never shown
Stickers are pictures (stickers) with which you can express your emotions.
It's almost like emoticons, only much cooler. Telegram stickers are completely free to use.
All the best Telegram stickers can be found in the sticker directory. You can also use the built-in Telegram @sticker bot.
It is enough to type @sticker in the message input field and select the emoticon with the emotion you need. The bot will offer you some of the most suitable stickers for this situation to choose from. nine0005
Everyone can create their own set of stickers. To do this, write to the @stickers bot and follow its instructions.
/newpack and enter the name of your future pack. It can be anything.
The maximum number of stickers in one set is 120 pieces. nine0022 /publish to the bot and enter a short name for the pack (this name will be contained in a link that all your friends can then install this pack for themselves). The name must be written in Latin letters and must not be shorter than four characters. It may be that the name you want to use is already taken. Then the bot will tell you about it, and you will have to choose a different name.
Video stickers are video files saved in a special format that supports transparency. Learn more about video stickers in a special section.
Animated stickers are created in Adobe After Effects using a special plug-in.
Read more about this in a separate article. nine0005
The dialing address must be five characters or more and must start with a letter. The first part of the address ( t.me/addstickers ) is not required.
The file must be in PNG or * WebP format with a transparent background. The image must fit into a 512×512 square (one side is 512 pixels, the other is 512 or less). nine0005
To make your sticker look equally good on any background, we recommend adding a white stroke and shadow to the image, as in this example.
For any operations with your set, you need to contact the @stickers robot.
To remove a sticker from a set, send the command /delsticker to the robot and then send the sticker you would like to remove.
To add a new sticker to an already created set, send the command 9 to the robot0020 /addsticker , then send him the link to your pack (to which you want to add the sticker). Well, then according to the old scheme, send a picture to the bot, and then a smiley.
Also, the robot functions allow you to view the download statistics of your set.
To remove a pack, send the command /delpack to the @stickers bot. Please note that after deletion, the set will remain with those users who have already installed it. New users will not be able to install it. nine0005
The set name cannot be changed. This problem can only be solved by creating the set again (already with the desired name).
The maximum number of stickers in one set is 120 pieces.
Recently, there have been more cases when a link to a favorite set suddenly stopped working.
Most likely, this set was removed from Telegram at the request of the copyright holders (copyright violation). nine0005
Unfortunately not. Only the creator of the set can view statistics, as well as perform any other actions with the set (delete or add stickers).
All sticker packs in Telegram are public. However, if you do not share a link to your set with anyone, then no one else will see it.
To do this, use the command /ordersticker in the @stickers bot.
You can link a set of stickers in the group settings. This only works in groups with more than 200 people.
Stickers are funny pictures that have replaced the usual emoticons that can be used in any kind of correspondence.
With their help, you can convey absolutely any emotions that cannot be expressed using text, and just brighten up communication and cheer up a little is never superfluous. nine0005
The Telegram messenger, like any other similar applications and services, has excellent support for such pictures. They can be installed almost unlimited. In one of our articles (by the way, you can find it here) we wrote how you can create a set of drawings yourself. If you don’t want to go too deep, and you are quite satisfied with the existing sets, then carefully read the instructions in this article. Here we will tell you how to quickly and easily find any picture, how to add stickers to Telegram for later use, and how to remove an unnecessary or unused package. nine0005
In order to find and add any new sticker you like to your Telegram, you can use one of the following methods:
What is needed for this? Click on the picture itself, then add it by selecting "Add sticker". The program will upload it to your account, after which it will be displayed in the emoji selection menu. nine0022 what remove it from there.