Skip to content

[MEDIUM] Monkey Patching Discord Gateway - main.py #56

@galpt

Description

@galpt

🟡 Medium: Monkey Patching Discord Gateway

Problem Description

The code monkey-patches discord.gateway.DiscordWebSocket.identify to detect mobile users:

# main.py lines 65-106
# added a monkey patch so the bot can show a mobile status.
original_identify = discord.gateway.DiscordWebSocket.identify


async def patched_identify(self):
    payload = {
        "op": self.IDENTIFY,
        "d": {
            "token": self.token,
            "properties": {
                "$os": "Android",
                "$browser": "Discord Android",
                "$device": "Android",
                # ...
            },
            # ...
        }
    }
    # ...


discord.gateway.DiscordWebSocket.identify = patched_identify

Issues

  1. Fragile — Breaks if Py-cord changes internal implementation
  2. Discord TOS — May violate Discord's terms of service for bot impersonation
  3. Not usedoriginal_identify is stored but never used

Exact Location

Recommended Fix

Remove the monkey-patch if not essential, or add version guards and document the dependency.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions