Discord channel message check, aggregation, and sending CLI for humans and AI agents
pip install discord-message-cli Copy PIP instructions
権限を持つ Discord チャンネルのメッセージを Discord 公式 HTTP API (v10) で取得・期間別集計・投稿する CLI ツールです。 人がターミナルで表を確認するほか、AI エージェントやスクリプトが JSON 形式で安全に集計・投稿結果のメタデータだけを取得できるように設計されています。
Python 3.10 以上が必要です。pipx または pip でワンコマンド導入できます。
# PyPI から導入する場合(推奨) pipx install discord-message-cli # または pip install discord-message-cli # GitHub リポジトリから直接導入する場合 pipx install git+https://github.com/IT-Engineer-K/discord-message-cli.git # ローカルのクローンから導入する場合 pipx install . 認証設定 実行前に環境変数 DISCORD_BOT_TOKEN を設定するか、実行時に --prompt-token を指定してください。
# PowerShell で一時的に環境変数へ設定する例 $env:DISCORD_BOT_TOKEN = (Read-Host -AsSecureString "Bot Token" | ConvertFrom-SecureString -AsPlainText) 必要な Discord Bot 権限: 対象チャンネルに対する View Channel(チャンネルを見る)、Read Message History(メッセージ履歴を読む・check/stats 用)、および Send Messages(メッセージを送信・send 用)。 ※ 接頭辞(--prefix)やキーワード(--keyword)による本文絞り込みを行う場合は、Discord Developer Portal で Bot の Message Content Intent を有効にしてください。
# 表形式(既定) discord-msg check --channel 123456789012345678 # AI / スクリプト向け JSON 形式 discord-msg check --channel 123456789012345678 --format json # トークンを対話的非表示入力で渡す場合 discord-msg check --channel 123456789012345678 --prompt-token JSON 出力例:
{ "ok": true, "channel_id": "123456789012345678", "reachable": true, "history_readable": true, "has_messages": true } 2. 期間別集計 (stats) 指定期間のメッセージ件数を集計します。
# 直近24時間の時間別集計(日本時間・表形式) discord-msg stats --channel 123456789012345678 # 期間と接頭辞・キーワードを指定して AI 向け JSON で取得 discord-msg stats ` --channel 123456789012345678 ` --since 2026-11-18T00:00:00+09:00 ` --until 2026-11-19T00:00:00+09:00 ` --by hour ` --prefix "[ALERT]" ` --keyword "DiskHigh" ` --format json JSON 出力例:
{ "channel_id": "123456789012345678", "period": { "start": "2026-11-18T09:00:00+09:00", "end": "2026-11-18T12:00:00+09:00" }, "timezone": "Asia/Tokyo", "granularity": "hour", "filter": { "prefix": "[ALERT]", "keyword": "DiskHigh", "ignore_case": false }, "buckets": [ { "label": "2026-11-18 09:00", "start": "2026-11-18T09:00:00+09:00", "end": "2026-11-18T10:00:00+09:00", "count": 2 }, { "label": "2026-11-18 10:00", "start": "2026-11-18T10:00:00+09:00", "end": "2026-11-18T11:00:00+09:00", "count": 0 }, { "label": "2026-11-18 11:00", "start": "2026-11-18T11:00:00+09:00", "end": "2026-11-18T12:00:00+09:00", "count": 3 } ], "total": 5, "scanned_in_period": 8 } 3. メッセージ投稿 (send) 指定チャンネルにメッセージを投稿します。デフォルトではすべてのメンション(@everyone / @here / ユーザー / ロール)が無効化されます。
# 位置引数または --message (-m) で投稿(メンションはデフォルト禁止) discord-msg send --channel 123456789012345678 "バッチ処理が完了しました" discord-msg send --channel 123456789012345678 -m "バッチ処理が完了しました" --format json # 標準入力から本文を渡して投稿 "複数行のメッセージ" | discord-msg send --channel 123456789012345678 --stdin # メンションを明示的に許可する場合のみ --allow-mentions を指定 discord-msg send --channel 123456789012345678 "@here 緊急アラート" --allow-mentions JSON 出力例:
{ "channel": "123456789012345678", "tz": "Asia/Tokyo" } 終了コード一覧 終了コード エラーコード 意味 0 - 正常終了(履歴が空の場合も含む) 2 INVALID_ARGS 引数・期間指定・設定ファイルの形式エラー 3 AUTH_FAILED トークン未指定または認証失敗 (401 Unauthorized) 4 PERMISSION_DENIED チャンネル閲覧・履歴読み取り権限不足 (403 Forbidden) 5 NOT_FOUND チャンネルが存在しないかアクセス不可 (404 Not Found) 6 RATE_LIMITED レート制限の再試行上限超過 (429 Too Many Requests) 7 FETCH_FAILED 通信エラーやページ送り途中の API エラー(不完全な集計は返さない) テストの実行 テストにはすべて架空のチャンネル ID・架空の通知データを使用しており、外部通信を行わずに実行できます。
$env:PYTHONPATH="src" python -m unittest discover -s tests -v Key dates PyPI data Data sourced directly from PyPI's database. Released: Nov 19, 2026 Latest release 1 maintainer PyPI data Data sourced directly from PyPI's database. funaharakoju Provenance Data verified by PyPI on Nov 19, 2026 Data provided by the project maintainers and verified by PyPI at the time of upload. Full provenance
Both files in this release have provenance metadata.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Both files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




