Warning: Class 'TelegramClient' does not define '__await__', so the 'await' operator cannot be used on its instances
Hi! I have symple script to copy messages from one telegram channel to another. How to go away from pycharm warning (Class 'TelegramClient' does not define '__await__', so the 'await' operator cannot be used on its instances)?
from telethon import TelegramClient, events
import asyncio
# Replace these with your own values
api_id = int('YOUR_API_ID')
api_hash = 'YOUR_API_HASH'
source_channel_username = 'source_channel_username' # Public channel username
destination_channel_id = 'destination_channel_id' # Your channel ID
# Create the client and connect
client = TelegramClient('anon', api_id, api_hash)
@client.on(events.NewMessage(chats=source_channel_username))
async def handler(event):
try:
await client.forward_messages(destination_channel_id, event.message)
print(f"Forwarded message: {event.message.text}")
except Exception as e:
print(f"Failed to forward message: {str(e)}")
async def main():
await client.start()
print("Client is running...")
await client.run_until_disconnected()
if __name__ == '__main__':
asyncio.run(main())
Please sign in to leave a comment.