I am working on a Telegram bot that is intended to share images from a specific subreddit, but I’m encountering an error that I am unable to resolve. Although I can’t disclose certain sensitive information for security reasons, I believe that it is not crucial for understanding the problem. Here’s a snippet of my code:
session_instance = <aiohttp.ClientSession object at 0x00000123456789AB>
config.py:
settings = {
"CLIENT_KEY": "(hidden)",
"SECRET_KEY":"(hidden)",
"API_KEY":"(hidden)"
}
telegram_bot.py:
import asyncio
import aiohttp
import config
import asyncpraw
from aiogram import Bot, types
TOKEN = config.settings["API_KEY"]
CHANNEL = -1001234567890
bot = Bot(token=TOKEN, parse_mode=types.ParseMode.HTML)
reddit_instance = asyncpraw.Reddit(client_id=config.settings["CLIENT_KEY"],
client_secret=config.settings["SECRET_KEY"],
user_agent="subreddit_bot/0.1")
memes_list = []
DELAY = 5
TARGET_SUBREDDIT = "memes"
LIMIT = 1
async def post_message(channel_id: int, content: str):
await bot.send_message(channel_id, text=content)
async def execute():
while True:
await asyncio.sleep(DELAY)
submissions = await reddit_instance.subreddit(TARGET_SUBREDDIT)
new_memes = submissions.new(limit=LIMIT)
meme_item = await new_memes.__anext__()
if meme_item.title not in memes_list:
memes_list.append(meme_item.title)
await post_message(CHANNEL, meme_item.url)
asyncio.get_event_loop().run_until_complete(execute())
Can anyone help me identify the problem?