Termux上でPython製Discord botを検出・起動・監視するためのツールです。 / A tool for discovering, starting, and monitoring Python-based Discord bots on Termux.
Termux bot ManagerはTermux上でPython製Discord botをまとめて管理するためのツールです。
指定ディレクトリを再帰的に探索し、特定のタグを含む .py ファイルを検出して起動します。
また、定期的な監視、再スキャン、キャッシュ管理、Discord Webhook通知を行います。
Tip
複数の Discord bot を同じ環境でホストしている方に特におすすめです。
- タグベースの自動検出: 指定ディレクトリ内を再帰的に検索し、特定のタグが記述されたPythonスクリプトを自動でbotとして認識します。
- プロセス監視と自動起動: 検出したbotを起動し、定期的な監視サイクルによってプロセスの状態をチェックします。
- 定期再スキャンとキャッシュ自動整理: 新しく追加されたbotの自動検出に加え、削除・移動されたファイルのキャッシュ削除を自動で行います。
- Discord Webhook 通知: botの起動、異常終了、新規検出、キャッシュ削除などの各種イベントを Discord へリアルタイムに通知します。
- Bot ごとの独立したログ管理: 各botのディレクトリ内に標準出力(
bot_stdout.log)と標準エラー(bot_stderr.log)を分離して保存します。
- Node.js
- Python 3
- Termux
- Discord Webhook URL(通知を使う場合)
Termux上でインストールするには、Gitの導入とnpmの設定が必要です。
事前準備
pkg install git
npm config set allow-git all方法1: npmから直接インストール(推奨)
npm install -g DovahkiinYuzuko/termux-bot-manager方法2: git cloneを使う方法
環境によって方法1でエラーになる場合は、以下の手順を試してください。
git clone [https://github.com/DovahkiinYuzuko/termux-bot-manager.git](https://github.com/DovahkiinYuzuko/termux-bot-manager.git)
cd termux-bot-manager
npm install -g .インストール完了後、pybot コマンドが利用可能になります。
初回起動時に config.json が存在しない場合は、テンプレートが自動生成されます。
生成後に内容を編集してから再度起動してください。
config.json の例:
{
"searchDirectory": "",
"targetTags": ["@discordbot", "@auto"],
"checkIntervalMinutes": 5,
"rescanIntervalMinutes": 60
}searchDirectory: botを探索する対象ディレクトリです。targetTags: Pythonファイル内に含まれていればbotとみなすタグです。checkIntervalMinutes: 監視サイクルの実行間隔です。rescanIntervalMinutes: 新規 bot 検出のための再スキャン間隔です。未指定の場合はcheckIntervalMinutesの値が使われます。
.env.sample をコピーして .env を作成し、値を設定してください。
cp .env.sample .env以下の値を設定できます。
DISCORD_WEBHOOK_URL=DISCORD_WEBHOOK_URL: Discord 通知の送信先 Webhook URL です。未設定の場合、通知は送信されません。
設定ファイルと環境変数を準備したあと、以下のコマンドで起動します。
pybot開発時など、直接実行する場合は以下でも起動できます。
node index.jsこのツールは、指定ディレクトリ以下の .py ファイルを探索し、
ファイル内容に targetTags のいずれかが含まれている場合、そのファイルをbotとして扱います。
Important
ツールに bot として認識させるため、対象の Python ファイル内に 事前にタグを記述しておく 必要があります。 指定のワード(タグ)が含まれていれば起動対象になるため、記述する形式はコメントなど何でも構いません。
例:
# tag: @discordbotcache.json: 検出済みbotパスのキャッシュです。bot_stdout.log: 各botディレクトリに出力される標準出力ログです。bot_stderr.log: 各botディレクトリに出力される標準エラーログです。
Discord Webhook を設定すると、以下のような通知を送信できます。
- botの起動
- botの異常終了
- bot起動時のエラー
- キャッシュからの削除
- 新規bot検出
- その他の情報通知
Note
Termux 環境では、Python ライブラリの導入方法によってインストール時間や成功率が大きく変わることがあります。
特に C コンパイル拡張を含むライブラリでは、この違いが重要です。
pip installは利用できますが、C コンパイル拡張を含むライブラリでは Termux 上でソースビルドが走ることがあります。- その場合、非力な CPU 環境では数分から数十分かかることがあります。
- たとえば
Pillowやmatplotlibでは、この問題が起こることがあります。 pkgで導入できるライブラリは、Termux 向けにビルド済みパッケージが提供されていることがあり、pipより大幅に速く導入できる場合があります。- そのため、まず
pkg search <ライブラリ名>で存在を確認し、見つかる場合はpkg installを優先することをおすすめします。 pkgに存在しない場合はpip installを使用してください。- ただし、
pkg版とpip版ではバージョン差がある場合があるため、厳密なバージョン指定が必要なプロジェクトでは注意が必要です。
Warning
- このツールは Python ファイル名やプロセス状態をもとに bot を管理します。
- 対象は Python 製 Discord bot を想定しています。
- 実行環境や運用方法によっては、意図しない判定が起こる可能性があります。
- Termux 上での利用を前提にしています。
- Python bot 側の依存関係や実行要件は、このツールとは別に準備してください。
このプロジェクトのライセンスは MIT License です。詳しくは LICENSE.MIT をお読みください。
Termux bot Manager is a tool for managing Python-based Discord bots on Termux.
It recursively scans a target directory, detects .py files containing specific tags, and starts them.
It also performs periodic monitoring, rescanning, cache management, and Discord Webhook notifications.
Tip
Highly recommended for those hosting multiple Discord bots in the same environment!
- Tag-based Auto Detection: Recursively searches target directories and automatically identifies Python scripts containing specified tags as bots.
- Process Monitoring & Auto-Start: Launches detected bots and continuously monitors process status via periodic check cycles.
- Periodic Rescan & Cache Cleanup: Automatically scans for newly added bots and prunes missing or deleted files from the cache.
- Discord Webhook Notifications: Sends real-time alerts to Discord for events such as startups, crashes, new bot detections, and cache removals.
- Isolated Per-Bot Logging: Saves standard output (
bot_stdout.log) and standard error (bot_stderr.log) logs independently inside each bot's directory.
- Node.js
- Python 3
- Termux
- Discord Webhook URL (if notifications are used)
To install this package on Termux, Git and a specific npm configuration are required beforehand.
Prerequisites
pkg install git
npm config set allow-git allMethod 1: Direct installation via npm (Recommended)
npm install -g DovahkiinYuzuko/termux-bot-managerMethod 2: Installation via git clone
If the above method fails depending on your environment, try the following steps:
git clone [https://github.com/DovahkiinYuzuko/termux-bot-manager.git](https://github.com/DovahkiinYuzuko/termux-bot-manager.git)
cd termux-bot-manager
npm install -g .After installation, the pybot command will be available.
If config.json does not exist on first launch, a template is created automatically.
Please edit it before starting the application again.
Example config.json:
{
"searchDirectory": "",
"targetTags": ["@discordbot", "@auto"],
"checkIntervalMinutes": 5,
"rescanIntervalMinutes": 60
}searchDirectory: The target directory to scan for bots.targetTags: Tags used to identify Python files as bots.checkIntervalMinutes: Interval for the monitoring cycle.rescanIntervalMinutes: Interval for rescanning and detecting new bots. If omitted, the value ofcheckIntervalMinutesis used.
Copy .env.sample to .env and set the values.
cp .env.sample .envYou can set the following value in .env:
DISCORD_WEBHOOK_URL=DISCORD_WEBHOOK_URL: The Discord Webhook URL used for notifications. If it is not set, notifications are not sent.
After preparing the configuration file and environment variables, start the application with:
pybotFor development or direct execution, you can also run:
node index.jsThis tool scans .py files under the target directory.
If a file contains any of the values listed in targetTags, it is treated as a bot.
Important
To allow the tool to recognize your bot, you must add a tag to the target Python file beforehand. The format can be anything, such as a simple comment, as long as it contains the specified word.
Example:
# tag: @discordbotcache.json: Cache file for detected bot paths.bot_stdout.log: Standard output log written in each bot directory.bot_stderr.log: Standard error log written in each bot directory.
When a Discord Webhook is configured, the tool can send notifications for:
- bot startup
- unexpected bot exit
- bot startup errors
- cache removal
- new bot detection
- other informational events
Note
On Termux, the installation method for Python libraries can significantly affect both installation time and reliability.
This is especially important for libraries that include C extension builds.
pip installworks, but libraries with C extensions may trigger source builds on Termux.- On low-power CPUs, this can take several minutes or even much longer.
- Libraries such as
Pillowandmatplotlibcan fall into this category. - Libraries available through
pkgmay be distributed as prebuilt packages for Termux, which can make installation much faster thanpip. - For this reason, it is recommended to first check with
pkg search <library-name>, and usepkg installwhen available. - If the package is not available through
pkg, usepip install. - However, package versions may differ between
pkgandpip, so projects requiring strict version control should verify compatibility carefully.
Warning
- This tool manages bots based on Python file names and process state.
- It is intended for Python-based Discord bots.
- Depending on the runtime environment and operational setup, unintended matches or detections may occur.
- It is intended for use on Termux.
- Dependencies and runtime requirements for each Python bot must be prepared separately.
This project is licensed under the MIT License. Please read LICENSE.MIT for details.
