Created
January 31, 2026 09:19
-
-
Save Breta01/246605c607201d1dd956ccb7c8895c61 to your computer and use it in GitHub Desktop.
AI for monitoring discord messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Requires followng packages: | |
| # pip install apify-client langchain-google-genai | |
| from apify_client import ApifyClient | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| # API TOKENS (TODO: Fill these) | |
| APIFY_TOKEN = '...fill in...' | |
| DISCORD_TOKEN = '...fill in...' | |
| GOOGLE_API_KEY = '...fill in...' | |
| client = ApifyClient(APIFY_TOKEN) | |
| # Prepare the Actor input (TODO: Update as needed) | |
| run_input = { | |
| "channelUrl": "https://discord.com/channels/927873274136891392/927873274136891398", | |
| "discordToken": DISCORD_TOKEN, | |
| "maxMessagesPerCrawl": 100, | |
| } | |
| run = client.actor("felt/discord-message-scraper").call(run_input=run_input) | |
| # Fetch and print Actor results from the run's dataset (if there are any) | |
| msgs_result = list(client.dataset(run["defaultDatasetId"]).iterate_items()) | |
| for item in msgs_result[:20]: | |
| date = item['timestamp'].split('T')[0] | |
| print(f'{item["author"]["username"]} ({date}): {item["content"]}') | |
| ### Message Processing ### | |
| llm = ChatGoogleGenerativeAI( | |
| model="gemini-3-flash-preview", | |
| temperature=0, | |
| max_tokens=None, | |
| timeout=None, | |
| max_retries=2, | |
| api_key=GGOOGLE_API_KEY, | |
| ) | |
| formatted_msgs = [] | |
| for item in msgs_result: | |
| date = item['timestamp'].split('T')[0] | |
| formatted_msgs.append( | |
| f'{item["author"]["username"]} ({date}): {item["content"]}' | |
| ) | |
| prompt = ([ | |
| ("system", | |
| "You extract important news from chat transcripts. " | |
| "Important news includes: breaking changes, launches, outages/incidents, deadlines, " | |
| "policy/legal changes, security vulnerabilities, major business events. " | |
| "Do NOT invent. If none, say 'No important news found.'"), | |
| ("human", | |
| "From this transcript, list any important news items.\n\n{transcript}\n\n" | |
| "For each item, include:\n" | |
| "- What happened\n" | |
| "- Why it matters\n" | |
| "- Supporting message IDs\n"), | |
| ("human", "\n\n".join(formatted_msgs)) | |
| ]) | |
| response = llm.invoke(prompt) | |
| print(response.content[0]["text"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment