Skip to main content

Discord bot permission scanner - Analyzes discord.py code to detect required permissions and generate invite links

Project description

mper.py

Discord bot permission scanner - Analyzes discord.py code to detect required permissions and generate invite links.

discord.pyボットのコードを解析し、必要な権限を検出して招待リンクを生成するツールです。

Features / 機能

  • Method-based detection (PRIMARY): Detects discord.py method calls (.ban(), .kick(), .send(), etc.) and infers required BOT permissions
  • Evidence tracking: Shows which method calls at which lines require which permissions
  • All 49 Discord permissions: Supports all Discord API permissions (as of 2025-12-22)
  • Context-aware detection: Handles member.edit(nick=...), member.edit(mute=...), etc.
  • Decorator support: @bot_has_permissions (supplementary), @has_permissions (user requirements only)

Installation / インストール方法

pip install mper

Usage / 使い方

CLI

mper /path/to/bot/directory CLIENT_ID

ライブラリとして使用

import mper

# 簡単に招待URLを生成(CLIと同じ動作)
url = mper.generate_invite_url("./my_bot", client_id="123456789012345678")
print(url)

# 詳細なスキャン結果を取得
result = mper.scan_directory("./my_bot")
print(f"検出されたパーミッション: {result['invite_link_permissions']}")

# パーミッション名から整数値を計算
perm_int = mper.calculate_permission_integer(['send_messages', 'ban_members'])

# カスタム招待URLを作成
url = mper.create_invite_link(
    client_id="123456789012345678",
    permissions=perm_int,
    scopes=['bot', 'applications.commands']
)

詳細な使用例は examples/ を参照してください。

CLI Examples / 例

# Basic usage
mper /home/user/my_discord_bot 123456789012345678

# With detailed report
mper /home/user/my_discord_bot 123456789012345678 --report

# Verbose output
mper /home/user/my_discord_bot 123456789012345678 --verbose

# Exclude directories
mper /home/user/my_discord_bot 123456789012345678 --exclude tests docs

# Custom OAuth2 scopes
mper /home/user/my_discord_bot 123456789012345678 --scope bot --scope applications.commands

CLI Options / オプション

Option Description
--report Print detailed permissions report with evidence
--verbose, -v Show detailed output during scanning
--no-inferred Only use declared permissions (from decorators)
--exclude Additional directories to exclude
--scope OAuth2 scopes for invite link (default: bot, applications.commands)
--output, -o Output file for invite link (default: bot_invite_url.txt)

Output Example / 出力例

======================================================================
DETECTED PERMISSIONS (from method calls - PRIMARY)
----------------------------------------------------------------------

ban_members (0x4):
  bot.py:15 -> member.ban()
    [high] Ban a member from the guild

manage_messages (0x2000):
  bot.py:25 -> channel.purge()
    [high] Bulk delete messages

======================================================================
INVITE LINK PERMISSIONS
======================================================================
Source: method-based detection + @bot_has_permissions

  Permissions: ban_members, manage_messages, send_messages
  Integer: 10246
  Hex: 0x2806

How It Works / 仕組み

  1. Method-based detection (PRIMARY): Scans Python AST for discord.py method calls and maps them to required permissions
  2. @bot_has_permissions (SUPPLEMENTARY): Explicit bot permission declarations are added to invite link
  3. @has_permissions (REFERENCE ONLY): User permission requirements are shown in report but NOT included in invite link

Supported Permissions / 対応権限

All 49 Discord permissions are supported (bits 0-46, 49-50). See Discord API Documentation for details.

License / ライセンス

This project is licensed under the MIT License. See LICENSE for details.

このツールはMITライセンスのもとで公開されています。複製、編集、再公開は基本的に全て許可されています。

Issues / 質問や不具合の報告

Please create issues with appropriate tags:

  • bug - Bug reports / バグ報告
  • enhancement - Feature requests / 要望
  • question - Questions / 質問

Credits / クレジット

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mper-1.1.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mper-1.1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file mper-1.1.0.tar.gz.

File metadata

  • Download URL: mper-1.1.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mper-1.1.0.tar.gz
Algorithm Hash digest
SHA256 64aca6dcc87f210d17e2fbcd9d963697d67769af30982dc560c65dee82fc01a0
MD5 4d3cff433727e9f13950afef35a3765b
BLAKE2b-256 6af4033ce4cc5385153fee0cd005ee41b98651c0565bc9a6663bd06ef984e74b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mper-1.1.0.tar.gz:

Publisher: publish.yml on easy-make-invite-url-for-discord-bot/mper.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mper-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: mper-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mper-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf67e0d509163df588d8a3694188940fd37834148a889e150a1ff06d23998ccd
MD5 eea891cdb8d6113fd0832efb4c4245e7
BLAKE2b-256 59ba886d578d248450ea7da40754ae55323ff3769b79fd7e65666ef9d483eed2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mper-1.1.0-py3-none-any.whl:

Publisher: publish.yml on easy-make-invite-url-for-discord-bot/mper.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page