A lightweight, interactive CLI tool that monitors any TikTok user's activity and sends real-time updates to your messaging destinations β Discord (webhook or bot) and Telegram bots are supported out of the box.
Made with β€οΈ by @k0shir0
- π¬ New Video Alerts β Get notified when a monitored user posts a new TikTok.
- π€ Follower Monitoring β Detects follower gains and drops.
- π Stat Tracking β Periodic summary of follower count, total likes, and video count.
- π¬ Multiple Messaging Providers β Fan out alerts to Discord webhooks, Discord bots, and Telegram bots at the same time.
- ποΈ Active Comment Scraping (opt-in) β Continuously collect every comment on every video of the monitored account into a local SQLite database.
- π€ Bot Commands (opt-in) β Ask the Discord or Telegram bot for comment analytics (
/comments) or the whole database as a file (/dump). Restricted to one authorized user ID per platform. - π οΈ Interactive CLI Setup β Pick destinations, enter credentials, validate, and send a test message before anything is saved.
- π Persistent Config β Reuse your settings or reconfigure anytime.
| Provider | Needs | Notes |
|---|---|---|
| Discord webhook | Webhook URL | The original integration. Server Settings β Integrations β Webhooks. |
| Discord bot | Bot token + channel ID | Bot must be in the server with permission to post in the channel. |
| Telegram bot | Bot token + chat ID | Create the bot with @BotFather; numeric chat ID (groups may be negative). |
Alerts are delivered to every configured destination β if one provider is down or misconfigured, the others still receive their messages.
- In Discord: Server Settings β Integrations β Webhooks β New Webhook, then copy the URL.
- During setup choose Discord webhook and paste the URL (input is hidden).
- Create an app at the Discord Developer Portal, open the Bot tab and copy the token.
- Invite the bot to your server (OAuth2 β URL Generator with the
botscope andSend Messagespermission). - Enable Developer Mode in Discord, right-click the target channel β Copy Channel ID.
- During setup choose Discord bot and provide both values.
- In Telegram, chat with @BotFather: send
/newbot, follow the steps, copy the token. - Send your bot any message, then open
https://api.telegram.org/bot<your-token>/getUpdatesin a browser and copyresult[0].message.chat.id. For a group, add the bot to the group first (group IDs are negative).
Active Comment Scraping collects every comment on every video of the
monitored account into a local SQLite database (comments.db by default).
It is entirely optional β the default is disabled, and a disabled setup
never touches comment endpoints or creates a database.
When enabled, it:
- Discovers all videos of the monitored user.
- Performs an initial scrape, video by video, printing progress
(
Videos discovered / processed / Comments collected / New comments). - Keeps itself up to date: new-video alerts trigger an immediate scrape of that video, and an incremental pass re-scrapes stale or newly found videos on an interval (default 30 minutes; recent videos refresh more often).
- Deduplicates everything β rescraping updates likes/counts instead of inserting copies.
Per-video failures are isolated: one blocked or empty video never aborts the run.
With Active Scraping enabled you can also enable command listeners for
Discord and/or Telegram during setup. Commands are restricted to the single
authorized user ID configured per platform (stable platform IDs β never
usernames). Tokens and IDs can also come from *_BOT_TOKEN / *_USER_ID
environment variables for the current run.
| Command | What it does |
|---|---|
/dump |
Uploads your full comment database as a file (Discord attachment / Telegram document), with row counts in the caption. |
/dump <page> |
Shows the analytics summary as text instead of the file. |
/comments |
Analytics overview: totals, most-commented video, top commenter, most-liked comment. |
/comments <#index | url | id> [page] |
Browses one video's stored comments, best-liked first, 10 per page. |
/help |
Lists the commands. |
All statistics are computed with SQL aggregation inside SQLite β responses stay fast regardless of database size.
{
"active_scraping": {
"enabled": true,
"db_path": "comments.db",
"scrape_interval": 1800
},
"command_bots": {
"discord": { "enabled": true, "bot_token": "...", "user_id": "123456789012345678", "channel_id": "222333444555666777" },
"telegram": { "enabled": true, "bot_token": "...", "user_id": "98765432" }
}
}π Upgrading from an older version? Old
setup.jsonfiles keep working unchanged: missing sections default to disabled, and nothing new scrapes until you explicitly opt in via setup (R at startup) or by editingsetup.json.
git clone https://github.com/k0shir0/TiktokStalker.git
cd TiktokStalkerpip install -r requirements.txt
python -m playwright installπ¦ Node.js is not required. The current
TikTokApi(v7+) drives a real browser via Playwright, so you must runpython -m playwright installonce to download the browser engines.
TikTok now returns data only to requests carrying a valid msToken cookie:
- Open tiktok.com in your browser (logged in works best).
- Open DevTools β Application β Cookies β https://www.tiktok.com.
- Copy the value of the
msTokencookie.
Provide it either during the interactive setup, or via an environment variable:
export ms_token="paste-your-mstoken-here" # macOS/Linux
setx ms_token "paste-your-mstoken-here" # Windows (new shell)
β οΈ ms_tokenvalues expire. If TikTok starts returning empty responses, grab a fresh one.
python main.pyOn first run the interactive setup walks you through:
- The TikTok username to monitor (e.g.,
charlidamelio) - An optional
ms_token(hidden input) - One or more messaging destinations β each with credential prompts, validation, and an optional test message so you can confirm delivery before saving
Your configuration is saved to setup.json. On future launches you'll be asked:
"Do you want to (C)ontinue with this setup, (M)anage messaging destinations, or (R)econfigure everything?"
- C β continue with your saved configuration
- M β add / edit / remove messaging destinations without touching anything else
- R β reconfigure everything (e.g. to monitor a different user)
| Variable | Default | Description |
|---|---|---|
ms_token |
(none) | Your TikTok msToken cookie (required for TikTok to return data). |
POLL_INTERVAL |
60 |
Seconds between checks for new activity. |
STATS_HEARTBEAT |
3600 |
Seconds between periodic stat summaries (0 = only post on change). |
TIKTOK_BROWSER |
chromium |
Playwright browser engine (chromium, webkit, or firefox). |
TIKTOK_HEADLESS |
true |
Set to false if TikTok is bot-blocking your requests. |
Credential environment variables override the stored setup.json values for
the current run (handy for CI/secrets managers):
| Variable | Overrides |
|---|---|
DISCORD_WEBHOOK_URL |
Stored Discord webhook URL |
DISCORD_BOT_TOKEN, DISCORD_CHANNEL_ID |
Stored Discord bot credentials |
TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID |
Stored Telegram bot credentials |
DISCORD_BOT_TOKEN, DISCORD_USER_ID, DISCORD_COMMAND_CHANNEL_ID |
Command-bot credentials (*_COMMAND_CHANNEL_ID only affects the command listener) |
TELEGRAM_BOT_TOKEN, TELEGRAM_USER_ID |
Telegram command-bot credentials |
{
"username": "charlidamelio",
"ms_token": "optional-if-not-using-env-var",
"messaging": [
{ "provider": "discord_webhook", "webhook_url": "https://discord.com/api/webhooks/..." },
{ "provider": "discord_bot", "bot_token": "...", "channel_id": "123456789012345678" },
{ "provider": "telegram_bot", "bot_token": "...", "chat_id": "-1001234567" }
]
}This file is generated automatically after your first run and is git-ignored because it contains your credentials.
π Upgrading from an older version? A
setup.jsonthat only has a top-level"webhook"value is migrated automatically to the new format on first run β no action needed.
Providers live in messaging/ and register themselves in
messaging.PROVIDERS. Subclass MessagingProvider, define
name/label/config_spec, implement send(), and the interactive setup,
fan-out dispatch, validation, and secret redaction all pick it up automatically.
- π New TikTok Posted β with caption and a direct link to the video.
- β New Follower(s) / β Lost Follower(s) β with the delta and new total.
- π TikTok Stats β followers, total likes, and video count.
Messages render as rich embeds on Discord; Telegram receives HTML-formatted messages (bold title, escaped content, link previews disabled, auto-chunked at Telegram's 4096-character limit).
python -m pytestThe suite covers providers, config validation, formatting/escaping, fan-out,
legacy migration, the monitor loop, the interactive setup flow, the comment
database, the scraper, bot command handling, both command listeners, and
end-to-end Active Scraping flows. All network access is mocked by default; an
opt-in live smoke test runs against real platforms when you set
TIKTOKSTALKER_LIVE_E2E=1 plus TELEGRAM_BOT_TOKEN_E2E + TELEGRAM_CHAT_ID_E2E
and/or DISCORD_BOT_TOKEN_E2E + DISCORD_CHANNEL_ID_E2E.
The pre-existing offline script also still works:
python test_logic.pyTikTok returns empty responses / "they are detecting you're a bot": TikTok has strong anti-bot protection, especially from servers and datacenter IPs. Try, in order:
- A fresh
ms_tokenfrom a real browser session. TIKTOK_HEADLESS=false(requires a desktop/display).TIKTOK_BROWSER=webkit.- Running from a residential IP or via a residential proxy.
Discord webhook messages stop appearing: the webhook was likely deleted or the URL revoked β re-create it and update setup (choose M at startup).
Discord bot fails with 401: the token was reset in the Developer Portal β generate a new one and update your configuration.
Discord bot authenticated but nothing arrives: the bot lacks access to the
channel or the Send Messages permission β check the channel ID and the bot's
role permissions.
Telegram test message fails with "chat not found": you haven't sent the bot
a message yet, or the chat ID is wrong (group IDs include a minus sign). Send
any message to the bot first, then re-check getUpdates.
TikTokStalker relies on the unofficial TikTokApi
scraping library. You are responsible for ensuring your usage complies with
TikTok's Terms of Service, Discord's community guidelines, and Telegram's terms.
MIT License β use it freely, modify it responsibly.
Pull requests welcome! Open issues or improvements via GitHub Issues.