attachment.py¶
1# An API wrapper for Bale written in Python
2# Copyright (c) 2022-2024
3# Kian Ahmadian <devs@python-bale-bot.ir>
4# All rights reserved.
5#
6# This software is licensed under the GNU General Public License v2.0.
7# See the accompanying LICENSE file for details.
8#
9# You should have received a copy of the GNU General Public License v2.0
10# along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>.
11
12from bale import Bot, Message
13from bale.handlers import CommandHandler, MessageHandler
14from bale.checks import PHOTOS
15
16client = Bot("Your Token")
17
18@client.listen('on_ready')
19async def on_ready_handler():
20 print(client.user, "is Ready!")
21
22@client.handle(CommandHandler('photo'))
23async def photo_command(message: Message):
24 return await message.reply_photo(photo='./attachment.png', caption="This is a simple photo")
25
26@client.handle(MessageHandler(PHOTOS))
27async def save_photo_handler(message: Message):
28 file = open('./attachment.png', 'wb')
29 await message.photos[0].save_to_memory(file)
30 return await message.reply("I saved this image!")
31
32client.run()