### Install discum from PyPI Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Standard installation from the Python Package Index (PyPI). ```bash pip install discum ``` -------------------------------- ### Multi-Client Setup Reusing Build Number Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Optimizes initialization of multiple bot instances by reusing the client_build_number from the first client. ```python import discum # First client gets build number bot1 = discum.Client(token=token_list[0]) build_num = bot1._Client__super_properties['client_build_number'] # Subsequent clients reuse build number clients = [bot1] for token in token_list[1:]: clients.append(discum.Client(token=token, build_num=build_num)) ``` -------------------------------- ### Package Metadata in setup.py Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Defines the package name, description, URL, and author for the discum distribution. ```python NAME = 'discum' DESCRIPTION = 'A Discord API Wrapper for Userbots/Selfbots written in Python.' URL = 'https://github.com/Merubokkusu/Discord-S.C.U.M' AUTHOR = 'Merubokkusu' ``` -------------------------------- ### Check websocket-client Version Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Verifies the installed websocket-client version; the package requires exactly 0.59.0 to avoid gateway connection issues. ```bash pip show websocket-client ``` -------------------------------- ### Install with Python 3 and Python 2 pip Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Shows the correct pip command for Python 3 and Python 2 environments, as the package supports both 2.7 and 3.x. ```bash # Python 3 python3 -m pip install ... # Python 2 python2 -m pip install ... ``` -------------------------------- ### Event handling with gateway Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Complete gateway example that logs in, prints the logged-in user, and prints incoming messages. Uses auto_reconnect=True when starting the gateway. ```python import discum bot = discum.Client(token='your_token_here') @bot.gateway.command def message_handler(resp): if resp.event.ready_supplemental: user = bot.gateway.session.user print(f"Logged in as {user['username']}#{user['discriminator']}") if resp.event.message: m = resp.parsed.auto() channel_id = m['channel_id'] username = m['author']['username'] content = m['content'] print(f"Message in {channel_id}: {username} said '{content}'") # Start the gateway connection bot.gateway.run(auto_reconnect=True) ``` -------------------------------- ### Install discum with remote authentication extras Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Installs discum with the 'ra' extras to enable remote authentication capabilities such as QR code login. ```bash python -m pip install --user --upgrade git+https://github.com/Merubokkusu/Discord-S.C.U.M.git#egg=discum[ra] ``` -------------------------------- ### Install discum Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Install the discum library from GitHub. Use the basic command for standard installation, or the extended command to enable remote authentication features like QR code login. ```APIDOC ## Install discum ### Description Install the discum library from GitHub. Use the basic command for standard installation, or the extended command to enable remote authentication features like QR code login. ### Command ``` python -m pip install --user --upgrade git+https://github.com/Merubokkusu/Discord-S.C.U.M.git#egg=discum ``` ### Command (with remote authentication) ``` python -m pip install --user --upgrade -e git+https://github.com/Merubokkusu/Discord-S.C.U.M.git#egg=discum[ra] ``` ``` -------------------------------- ### discum.Client Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Initializes a new Discum client for interacting with Discord. Accepts various authentication methods and configuration options. ```APIDOC ## discum.Client ### Description Initializes a new Discum client for interacting with Discord. Accepts various authentication methods and configuration options. ### Method Constructor ### Endpoint `discum.Client` ### Parameters #### Constructor Parameters - **email** (Optional[str]) - Optional - Email for login authentication - **password** (Optional[str]) - Optional - Password for login authentication - **secret** (Optional[str]) - Optional - 2FA secret string - **code** (Optional[str]) - Optional - TOTP 6-digit code - **token** (Optional[str]) - Optional - User token for direct authentication - **remote_auth** (Optional[bool/str]) - Optional - Remote authentication (QR code) - **proxy** (Optional[str]) - Optional - Proxy server configuration - **user_agent** (Optional[str/list]) - Optional - Custom user agent string(s) - **locale** (Optional[str]) - Optional - Client locale setting (default: "en-US") - **build_num** (Optional[int]) - Optional - Discord build number (default: "request") - **log** (Optional[dict]) - Optional - Logging configuration (default: Console logging) ### Request Example ```python import discum bot = discum.Client(token="your_user_token_here") ``` ### Response #### Success Response Returns a `discum.Client` instance. #### Response Example ```python bot = discum.Client(token="your_user_token_here") ``` ``` -------------------------------- ### Install discum from GitHub Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Installs the latest version of discum directly from the GitHub repository using pip. Use the --user flag to install for the current user and --upgrade to update an existing installation. ```bash python -m pip install --user --upgrade git+https://github.com/Merubokkusu/Discord-S.C.U.M.git#egg=discum ``` -------------------------------- ### Complete Member Fetching Example Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Coordinates member fetching with discum's Gateway. Starts fetching with fetchMembers, registers a completion handler, runs the gateway until fetching finishes, then resets the session for subsequent runs. The handler prints the member count and closes the gateway. ```python import discum bot = discum.Client(token='your_token') def close_after_fetching(resp, guild_id): if bot.gateway.finishedMemberFetching(guild_id): members_count = len(bot.gateway.session.guild(guild_id).members) print(f'{members_count} members fetched') bot.gateway.removeCommand({ 'function': close_after_fetching, 'params': {'guild_id': guild_id} }) bot.gateway.close() def get_members(guild_id, channel_id): # Start member fetching bot.gateway.fetchMembers(guild_id, channel_id, keep="all", wait=1) # Register completion handler bot.gateway.command({ 'function': close_after_fetching, 'params': {'guild_id': guild_id} }) # Run gateway until fetching complete bot.gateway.run() bot.gateway.resetSession() # Optimization for subsequent runs return bot.gateway.session.guild(guild_id).members # Execute fetching members = get_members('guild_id', 'channel_id') ``` -------------------------------- ### Logging Configuration for discum.Client Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Configure console and file logging. Default is console-only; file logging writes to 'bot.log' and supports custom encoding. ```python # Console logging only (default) bot = discum.Client(token="token", log={"console": True, "file": False}) # File logging bot = discum.Client(token="token", log={"console": False, "file": "bot.log"}) # Both console and file with custom encoding bot = discum.Client(token="token", log={ "console": True, "file": "bot.log", "encoding": "utf-8" }) ``` -------------------------------- ### User Agent Configuration for discum.Client Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Set a single custom user agent or provide a list for random selection. Replace 'token' and user agent strings with your own. ```python # Single user agent bot = discum.Client(token="token", user_agent="Custom User Agent") # Random selection from list user_agents = [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/96.0.4664.110", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Safari/537.36" ] bot = discum.Client(token="token", user_agent=user_agents) ``` -------------------------------- ### Fetch Message Then Click Button (Approach 1) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Fetches a message to get its components, parses them with Buttoner, then clicks a button by label. Requires an existing message with components and a valid channelID, messageID, and guildID. ```python from discum.utils.button import Buttoner # Get message with components message = bot.getMessage(channelID, messageID) data = message.json()[0] # Parse button components buts = Buttoner(data["components"]) # Click specific button bot.click( data["author"]["id"], channelID=data["channel_id"], guildID=guildID, messageID=data["id"], messageFlags=data["flags"], data=buts.getButton("First"), ) ``` -------------------------------- ### Proxy Configuration for discum.Client Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Configure discum.Client to use HTTP, authenticated, or SOCKS proxies. Replace 'token' and proxy addresses with your own values. ```python # HTTP proxy bot = discum.Client(token="token", proxy="http://10.10.1.10:3128") # Authenticated proxy bot = discum.Client(token="token", proxy="http://username:password@10.10.1.10:3128") # SOCKS proxy bot = discum.Client(token="token", proxy="socks4://10.10.1.10:3126") ``` -------------------------------- ### Execute Member Fetching Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Starts member fetching with a 1-second wait between requests, registers the completion handler, runs the gateway, resets the session for future runs, and returns the fetched members. ```python def get_members(guild_id, channel_id): # Start member fetching with 1 second wait between requests bot.gateway.fetchMembers(guild_id, channel_id, keep="all", wait=1) # Register completion handler bot.gateway.command({ 'function': close_after_fetching, 'params': {'guild_id': guild_id} }) # Run gateway connection bot.gateway.run() # Clean up session data for future runs bot.gateway.resetSession() # Return fetched members return bot.gateway.session.guild(guild_id).members ``` -------------------------------- ### Install discum with remote authentication extras Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Installs discum with the 'ra' extra dependencies to enable remote authentication features such as QR code login. The -e flag installs in editable mode, and the extras are specified after the egg name. ```bash python -m pip install --user --upgrade -e git+https://github.com/Merubokkusu/Discord-S.C.U.M.git#egg=discum[ra] ``` -------------------------------- ### Basic DM Slash Command Example Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples Use for DM slash commands via REST API. Retrieves available commands, creates a SlashCommander instance, explores command structure, and triggers a slash command. ```python from discum.utils.slash import SlashCommander   # Get available slash commands for a bot slashCmds = bot.getSlashCommands(botID).json()   # Create SlashCommander instance s = SlashCommander(slashCmds)   # Explore command structure metadata = s.metadata(['saved', 'queues', 'create']) options = s.options(['saved', 'queues', 'create'])   # Construct and send command data = s.get(['saved', 'queues', 'create'], inputs={'name':'test'}) bot.triggerSlashCommand(botID, channelID, data=data) ``` -------------------------------- ### Basic message sending with REST Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Complete example of sending a message via the REST API. Requires a valid Discord token and channel ID. Prints the HTTP response status code. ```python import discum bot = discum.Client(token='your_token_here') # Send a message using REST API response = bot.sendMessage("238323948859439", "Hello Discord!") print(response.status_code) ``` -------------------------------- ### Basic Connectivity Test with discum.Client.checkToken Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.1-installation-and-setup Verifies token validity by checking the HTTP status code from checkToken; 200 indicates a valid token. ```python import discum # Test token validity bot = discum.Client(token="your_token") result = bot.checkToken("your_token") print(result.status_code) # Should be 200 for valid token ``` -------------------------------- ### Basic Gateway Event Response Pattern with @bot.gateway.command Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Registers an event handler using the @bot.gateway.command decorator. The handler checks for ready_supplemental to print login info and for message events to print message content. Run with bot.gateway.run(). ```python import discum bot = discum.Client(token='your_token') @bot.gateway.command def event_handler(resp): if resp.event.ready_supplemental: user = bot.gateway.session.user print(f"Logged in as {user['username']}#{user['discriminator']}") if resp.event.message: message_data = resp.parsed.auto() print(f"New message: {message_data['content']}") bot.gateway.run() ``` -------------------------------- ### Partial Range Fetching with startIndex and stopIndex Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Fetch members starting from a specific index (useful for resuming interrupted fetches), stop before a specific index, or fetch a specific range by combining both parameters. ```python # Start from specific index (useful for resuming interrupted fetches) bot.gateway.fetchMembers(guild_id, channel_id, startIndex=50, wait=1) # Stop before specific index bot.gateway.fetchMembers(guild_id, channel_id, stopIndex=200, wait=1) # Fetch specific range bot.gateway.fetchMembers(guild_id, channel_id, startIndex=100, stopIndex=300, wait=1) ``` -------------------------------- ### Command Detection Pattern Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.2-gateway-event-examples Handles incoming messages and processes commands starting with '!'. Uses the bot.gateway.command decorator and resp.parsed.auto() to parse the message content. ```python @bot.gateway.command def command_processor(resp): if resp.event.message: m = resp.parsed.auto() if m['content'].startswith('!'): command = m['content'][1:].split()[0] # Process command ``` -------------------------------- ### Gateway Event-Driven Button Click (Approach 2) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Uses a gateway event handler to detect messages with components and click a button without an extra API call. Requires a gateway session and a valid sessionID. ```python @bot.gateway.command def click_button_handler(resp): if resp.event.message or resp.event.message_updated: data = resp.parsed.auto() if "components" in data: buts = Buttoner(data["components"]) bot.click( data["author"]["id"], channelID=data["channel_id"], guildID=data.get("guild_id"), messageID=data["id"], messageFlags=data["flags"], data=buts.getButton("First"), sessionID=bot.gateway.session_id ) ``` -------------------------------- ### Session Data Access Patterns Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Accesses organized data structures from the Gateway session for users, guilds, DMs, and relationships. Uses bot.gateway.session.user, bot.gateway.session.guild(guild_id), bot.gateway.session.DM(channel_id), and bot.gateway.session.relationships. ```python # User data user_info = bot.gateway.session.user # Guild data guild_data = bot.gateway.session.guild(guild_id) guild_members = guild_data.members guild_channels = guild_data.channels # DM data dm_data = bot.gateway.session.DM(channel_id) # Relationship data relationships = bot.gateway.session.relationships ``` -------------------------------- ### Event Handler Registration and Removal Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Shows dynamic registration and removal of event handlers using bot.gateway.command and bot.gateway.removeCommand. Includes registering with parameters, removing a specific handler by function and params, and removing all handlers matching a function. ```python # Register handler with parameters bot.gateway.command({ "function": handler_function, "params": {"param1": "value1", "param2": "value2"} }) # Remove specific handler bot.gateway.removeCommand({ "function": handler_function, "params": {"param1": "value1"} }) # Remove all handlers matching function bot.gateway.removeCommand(handler_function) ``` -------------------------------- ### Complex Event Handler with State Management Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Handles multiple event types (ready_supplemental, message, message_updated) with shared state in a MessageProcessor class. Uses bot.gateway.command decorator and resp.parsed.auto() for data parsing. ```python class MessageProcessor: def __init__(self, bot): self.bot = bot self.processed_messages = set() self.target_phrases = ['turn me into a server'] @bot.gateway.command def process_events(self, resp): if resp.event.ready_supplemental: self._handle_ready(resp) elif resp.event.message: self._handle_message(resp) elif resp.event.message_updated: self._handle_message_update(resp) def _handle_message(self, resp): data = resp.parsed.auto() if self._should_process(data): self._create_response(data) ``` -------------------------------- ### Dropdown Menu Selection Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7-examples-and-tutorials Selects multiple options from a dropdown menu using Buttoner's getMenuSelection. Requires a parsed message with components and a placeholder matching the dropdown's placeholder. ```python # Select multiple options from dropdown bot.click( data["author"]["id"], channelID=data["channel_id"], guildID=guildID, messageID=data["id"], messageFlags=data["flags"], data=buts.getMenuSelection( placeholder="Make a selection", labels=['option1', 'option2'] ), ) ``` -------------------------------- ### Register a custom event handler with @bot.gateway.command Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/5.3-event-processing Use this pattern to register a function that processes incoming Gateway events. The handler receives a response object with `resp.event` for event type checking and `resp.parsed.auto()` for parsed data. The example checks for `message` and `guild_members_chunk` events. ```python @bot.gateway.command def event_handler(resp): if resp.event.message: # Handle message events message_data = resp.parsed.auto() elif resp.event.guild_members_chunk: # Handle member chunk events process_member_data(resp) ``` -------------------------------- ### HTTP Method Wrapper Patterns Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/6.1-extending-discum Each HTTP method uses a specific wrapper pattern with Wrapper.sendRequest. GET and DELETE do not require a body; POST, PUT, and PATCH do. The patterns are used in core wrapper implementations. ```python return Wrapper.sendRequest(self.s, 'get', url, log=self.log) ``` ```python return Wrapper.sendRequest(self.s, 'post', url, body, log=self.log) ``` ```python return Wrapper.sendRequest(self.s, 'put', url, body, log=self.log) ``` ```python return Wrapper.sendRequest(self.s, 'patch', url, body, log=self.log) ``` ```python return Wrapper.sendRequest(self.s, 'delete', url, log=self.log) ``` -------------------------------- ### sendMessage REST API method pattern Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/3.1-client-class Example of the lazy import pattern used by REST API methods in the Client class. The method delegates to a dedicated module, passing common parameters (discord, s, log) consistently, ensuring modules are only loaded when needed. ```python def sendMessage(self, channelID, message="", nonce="calculate", tts=False, embed=None, message_reference=None, allowed_mentions=None, sticker_ids=None): return imports.Messages(self.discord, self.s, self.log).sendMessage(channelID, message, nonce, tts, embed, message_reference, allowed_mentions, sticker_ids) ``` -------------------------------- ### Initialize Client and Gateway Connection Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Creates a discum client with a token. The client automatically sets up the Gateway connection infrastructure including the GuildCombo class accessible via bot.gateway. ```python import discum bot = discum.Client(token='your_token') ``` -------------------------------- ### Configure logging for discum.Client and gateway Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Sets up logging for the client with console and file output, then separately configures gateway event logging. Replace 'your_token' with a valid Discord token. The gateway log setting overrides the client-level log for gateway events. ```python bot = discum.Client( token='your_token', log={"console": True, "file": "discum.log"} ) # Separate logging for gateway events bot.gateway.log = {"console": True, "file": "gateway.log"} ``` -------------------------------- ### Initialize discum.Client with a user token Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Creates a discum client instance using a Discord user token. Replace 'your_user_token_here' with your actual token. The Client class is the main entry point for interacting with Discord. ```python import discum bot = discum.Client(token="your_user_token_here") ``` -------------------------------- ### Basic Member Fetching with Gateway Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/5.1-guild-member-fetching Sets up a completion handler that closes the gateway after fetching members, then runs the fetch and gateway. Use this pattern to retrieve all members of a guild and access them via bot.gateway.session.guild(guild_id).members. ```python @bot.gateway.command def close_after_fetching(resp, guild_id): if bot.gateway.finishedMemberFetching(guild_id): members = bot.gateway.session.guild(guild_id).members bot.gateway.close() bot.gateway.fetchMembers(guild_id, channel_id, wait=1) bot.gateway.command({'function': close_after_fetching, 'params': {'guild_id': guild_id}}) bot.gateway.run() ``` -------------------------------- ### Configure logging and handle errors in gateway command Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Sets up console/file logging for bot and gateway, then registers a robust handler that catches exceptions during message processing and logs errors. ```python # Configure logging for REST and Gateway bot.log = {"console": True, "file": "bot.log"} bot.gateway.log = {"console": True, "file": "gateway.log"} @bot.gateway.command def robust_handler(resp): try: if resp.event.message: m = resp.parsed.auto() # Process message safely if 'content' in m and 'author' in m: content = m['content'] author_id = m['author']['id'] # Handle message... except Exception as e: print(f"Error processing message: {e}") # Log error details ``` -------------------------------- ### Multi-Event Coordination Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.2-gateway-event-examples Handles multiple Gateway events in a single handler: ready_supplemental, message, reaction_added, and guild_member_updated. Useful for initializing state and responding to various events. ```python @bot.gateway.command def multi_event_handler(resp): if resp.event.ready_supplemental: # Initialize bot state pass elif resp.event.message: # Handle messages pass elif resp.event.reaction_added: # Handle reactions pass elif resp.event.guild_member_updated: # Handle member updates pass ``` -------------------------------- ### discum.Client(token=...) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Initialize the discum client with a Discord user token. This is the main entry point for interacting with the Discord API through discum. ```APIDOC ## discum.Client(token=...) ### Description Initialize the discum client with a Discord user token. This is the main entry point for interacting with the Discord API through discum. ### Method Constructor ### Endpoint `discum.Client` ### Parameters - **token** (str) - Required - Discord user token (primary authentication method) - **email** (str) - Optional - Email for login authentication - **password** (str) - Optional - Password for login authentication - **secret** (str) - Optional - 2FA secret string - **proxy** (str) - Optional - Proxy URL (http/https/socks4/socks5) - **user_agent** (str/list) - Optional - Custom user agent string or list for random selection - **build_num** (int) - Optional - Discord build number (defaults to auto-request) - **log** (dict) - Optional - Logging configuration ### Request Example ```python import discum bot = discum.Client(token="your_user_token_here") ``` ``` -------------------------------- ### SlashCommander.get(cmdList, inputs={}) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/4.4-modern-interactions Builds a complete command payload from a command list and optional input values. Returns a dictionary representing the full command payload. ```APIDOC ## SlashCommander.get(cmdList, inputs={}) ### Description Builds a complete command payload from a command list and optional input values. Returns a dictionary representing the full command payload. ### Method get ### Parameters - **cmdList** (list) - Required - List of command metadata objects. - **inputs** (dict) - Optional - Input values for command options. ### Returns - **dict** - Complete command payload. ``` -------------------------------- ### metadata(cmdList) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples Returns the command type and description for a given command hierarchy. Use this to understand the structure of a slash command. ```APIDOC ## metadata(cmdList) ### Description Returns the command type and description for a given command hierarchy. Use this to understand the structure of a slash command. ### Method metadata ### Parameters - **cmdList** (list of strings) - Required - The command hierarchy as a list of strings, e.g., `['saved', 'queues', 'create']`. ### Returns - Command type and description ``` -------------------------------- ### Simple REST-based button click with Buttoner Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples Fetches a message, parses its components with Buttoner, and clicks a button by label using bot.click(). Requires channelID, messageID, and guildID. ```python # Get message with buttons message = bot.getMessage(channelID, messageID) data = message.json()[0] # Parse button components buts = Buttoner(data["components"]) # Click a button by label bot.click( data["author"]["id"], channelID=data["channel_id"], guildID=guildID, messageID=data["id"], messageFlags=data["flags"], data=buts.getButton("First"), ) ``` -------------------------------- ### Gateway event handler and run Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Define event handlers with the @bot.gateway.command decorator and run the gateway to process real-time events. The handler checks for message events and prints a notification. ```python @bot.gateway.command def handle_events(resp): if resp.event.message: print("New message received!") bot.gateway.run() ``` -------------------------------- ### Access session data with @bot.gateway.command Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2-getting-started Use this snippet inside a gateway command to access session data after the ready_supplemental event. It prints the user ID and iterates over guild IDs to print each guild's name. Requires an initialized discum.Client and a connected gateway. ```python @bot.gateway.command def access_session_data(resp): if resp.event.ready_supplemental: # Access user info user = bot.gateway.session.user print(f"User ID: {user['id']}") # Access guild information for guild_id in bot.gateway.session.guildIDs: guild = bot.gateway.session.guild(guild_id) print(f"Guild: {guild.name}") ``` -------------------------------- ### SlashCommander.metadata(cmdList) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/4.4-modern-interactions Retrieves command metadata including type, description, and options from a command list. Returns a dictionary with the command's metadata. ```APIDOC ## SlashCommander.metadata(cmdList) ### Description Retrieves command metadata including type, description, and options from a command list. Returns a dictionary with the command's metadata. ### Method metadata ### Parameters - **cmdList** (list) - Required - List of command metadata objects. ### Returns - **dict** - Command type, description, and options. ``` -------------------------------- ### SlashCommander.options(cmdList) Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/4.4-modern-interactions Retrieves command parameters and their types from a command list. Returns a list of option objects. ```APIDOC ## SlashCommander.options(cmdList) ### Description Retrieves command parameters and their types from a command list. Returns a list of option objects. ### Method options ### Parameters - **cmdList** (list) - Required - List of command metadata objects. ### Returns - **list** - Command parameters and their types. ``` -------------------------------- ### Find Visible Channels with findVisibleChannels Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Finds visible channels for fetching using bot.gateway.findVisibleChannels(guild_id), then uses the first visible channel to call fetchMembers. ```python # Find visible channels for fetching visible_channels = bot.gateway.findVisibleChannels(guild_id) if visible_channels: channel_id = visible_channels[0] # Use first visible channel bot.gateway.fetchMembers(guild_id, channel_id) ``` -------------------------------- ### Message event handler with automated responses Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.2-gateway-event-examples Handles READY_SUPPLEMENTAL and MESSAGE_CREATE events. Ignores own messages, responds to specific content, and replies to replies referencing the bot. Uses bot.gateway.command decorator and resp.parsed.auto(). ```python @bot.gateway.command def message_handler(resp): if resp.event.ready_supplemental: user = bot.gateway.session.user print("Logged in as {}#{}".format(user['username'], user['discriminator'])) if resp.event.message: m = resp.parsed.auto() # Ignore own messages if m['author']['id'] == bot.gateway.session.user['id']: return # Process different message types if m['content'] == 'turn me into a server': bot.sendMessage(m['channel_id'], 'reply to one of my messages and I will make you a server :)') # Handle reply messages if m['type'] == 'reply': if 'referenced_message' in m and m['referenced_message']['author']['id'] == bot.gateway.session.user['id']: bot.reply(m['channel_id'], m['id'], "Response to your reply!") ``` -------------------------------- ### Client Method Integration Pattern Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/6.1-extending-discum Expose a core wrapper through the discum.Client class. The method passes self.discord (API base URL), self.s (requests session), and self.log (logging flag) to the module class. ```python def clientMethodName(self, parameters): return ModuleClass(self.discord, self.s, self.log).wrapperMethod(parameters) ``` -------------------------------- ### Optimize Fetching for Large Guilds Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Uses memory-efficient settings for large guilds: method="no overlap" for faster fetching, keep=['username', 'discriminator'] to minimize data, wait=1.5 to avoid rate limits, and considerUpdates=False to skip presence updates. ```python # Use memory-efficient settings bot.gateway.fetchMembers( guild_id, channel_id, method="no overlap", # Faster fetching keep=['username', 'discriminator'], # Minimal data wait=1.5, # Avoid rate limits considerUpdates=False # Skip presence updates ) ``` -------------------------------- ### Register gateway event handler with @bot.gateway.command Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Decorator-based event handler for Discord gateway events. Checks ready_supplemental to print login info and message events to print channel ID and content. ```python @bot.gateway.command def handle_events(resp): if resp.event.ready_supplemental: user = bot.gateway.session.user print("Logged in as {}#{}".format(user['username'], user['discriminator'])) if resp.event.message: m = resp.parsed.auto() channelID = m['channel_id'] content = m['content'] print("Message in {}: {}".format(channelID, content)) ``` -------------------------------- ### Access session data: user, guild, friends Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Retrieves current user info, guild data/members, and friends lists from the gateway session. Use after the gateway is connected and session data is populated. ```python # Access current user information user = bot.gateway.session.user print(f"Username: {user['username']}") # Access guild data guild_data = bot.gateway.session.guild("123456789").data members = bot.gateway.session.guild("123456789").members # Access friends and relationships friends = bot.gateway.session.friends online_friends = bot.gateway.session.onlineFriends ``` -------------------------------- ### Version tuple in discum/__version__.py Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/6.2-package-structure Defines the version as a tuple and converts it to a dot-separated string. Used when VERSION in setup.py is None. ```python VERSION = (1, 4, 1) __version__ = '.'.join(map(str, VERSION)) ``` -------------------------------- ### Respond to messages with REST API Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Registers a gateway command that responds to incoming messages via REST. Skips own messages, replies 'Hello there!' to 'hello', and echoes text after '!echo '. Ends with bot.gateway.run(auto_reconnect=True). ```python @bot.gateway.command def message_responder(resp): if resp.event.message: m = resp.parsed.auto() # Skip own messages if m['author']['id'] == bot.gateway.session.user['id']: return channel_id = m['channel_id'] content = m['content'] # Respond to specific content if content.lower() == 'hello': bot.sendMessage(channel_id, 'Hello there!') elif content.startswith('!echo '): echo_text = content[6:] # Remove '!echo ' bot.sendMessage(channel_id, echo_text) bot.gateway.run(auto_reconnect=True) ``` -------------------------------- ### Data Retention Control with keep Parameter Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Control which member properties are retained. Use keep="all" to keep everything, a list of specific properties to keep only those, or keep=[] to minimize memory usage for large guilds. Available properties include 'pending', 'deaf', 'hoisted_role', 'presence', 'joined_at', 'public_flags', 'username', 'avatar', 'discriminator', 'premium_since', 'roles', 'is_pending', 'mute', 'nick', 'bot', 'communication_disabled_until'. ```python # Keep all member properties bot.gateway.fetchMembers(guild_id, channel_id, keep="all") # Keep specific properties only bot.gateway.fetchMembers(guild_id, channel_id, keep=[ 'username', 'discriminator', 'nick', 'roles', 'joined_at' ]) # Minimal data (save memory for large guilds) bot.gateway.fetchMembers(guild_id, channel_id, keep=[]) ``` -------------------------------- ### Buttoner.findMenu() Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples Searches for a select menu component within parsed message components. Returns the menu data if found, otherwise null. ```APIDOC ## Buttoner.findMenu() ### Description Searches for a select menu component within parsed message components. Returns the menu data if found, otherwise null. ### Method findMenu ### Parameters - **placeholder** (string) - Optional - The placeholder text of the menu. - **customID** (string) - Optional - The custom ID of the menu. - **row** (number) - Optional - The row index of the menu. ### Returns - Menu data object if found, otherwise null. ``` -------------------------------- ### Gateway lifecycle control methods Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Controls the gateway connection: run with auto-reconnect, close, reset session data, and send raw payloads. Use these to manage the connection lifecycle. ```python # Start the gateway connection bot.gateway.run(auto_reconnect=True) # Close the gateway connection bot.gateway.close() # Reset session data bot.gateway.resetSession() # Send raw payload to gateway bot.gateway.send({"op": 1, "d": 0}) ``` -------------------------------- ### Rate Limiting Management with wait Parameter Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Add wait time between requests to avoid rate limits, or set wait=None to disable rate limiting (higher risk of being rate-limited). ```python # Add wait time between requests to avoid rate limits bot.gateway.fetchMembers(guild_id, channel_id, wait=2.0) # No rate limiting (higher risk) bot.gateway.fetchMembers(guild_id, channel_id, wait=None) ``` -------------------------------- ### Access Fetched Data Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Calls get_members with a guild ID and a visible channel ID, then iterates over the returned members dictionary to print each member's username. ```python guild_id = '322850917248663552' channel_id = '754536220826009670' # Any visible channel in the guild members = get_members(guild_id, channel_id) # Access individual member data for member_id, member_data in members.items(): print(f"Member: {member_data.get('username', 'Unknown')}") ``` -------------------------------- ### Advanced Guild Slash Command with Gateway Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples For guild slash commands, integrates with Gateway events. Searches for slash commands, parses application commands, and triggers the command with session ID. ```python def slashCommandTest(resp, guildID, channelID, botID): if resp.event.ready_supplemental: # Search for slash commands bot.gateway.request.searchSlashCommands(guildID, limit=10, query="queue") if resp.event.guild_application_commands_updated: bot.gateway.removeCommand(slashCommandTest) slashCmds = resp.parsed.auto()['application_commands'] # Parse and trigger command s = SlashCommander(slashCmds, application_id=botID) data = s.get(['queue']) bot.triggerSlashCommand( botID, channelID=channelID, guildID=guildID, data=data, sessionID=bot.gateway.session_id )   # Register the command handler bot.gateway.command({ "function": slashCommandTest, "params": {"guildID": guildID, "channelID": channelID, "botID": botID} }) bot.gateway.run() ``` -------------------------------- ### Gateway-integrated button click with clickButton Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples Defines a callback for Gateway events that clicks a button when the message is from the bot and the interaction user is the bot's session user. Uses Buttoner and bot.click() with sessionID. ```python def clickButton(resp): if resp.event.message or resp.event.message_updated: data = resp.parsed.auto() if (data.get("webhook_id") == botID and data["interaction"]["user"]["id"] == bot.gateway.session.user["id"]): buts = Buttoner(data["components"]) bot.click( data["webhook_id"], channelID=data["channel_id"], guildID=data.get("guild_id"), messageID=data["id"], messageFlags=data["flags"], data=buts.getButton("First"), sessionID=bot.gateway.session_id ) ``` -------------------------------- ### Define Event Handler for Completion Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Defines a handler that checks if member fetching is complete using finishedMemberFetching(), prints the member count, removes the command, and closes the gateway connection. ```python def close_after_fetching(resp, guild_id): if bot.gateway.finishedMemberFetching(guild_id): member_count = len(bot.gateway.session.guild(guild_id).members) print(f'{member_count} members fetched') bot.gateway.removeCommand({ 'function': close_after_fetching, 'params': {'guild_id': guild_id} }) bot.gateway.close() ``` -------------------------------- ### @bot.gateway.command decorator Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/5.3-event-processing Registers a function as a Gateway event handler. The decorated function receives a response object with event classification and parsed data. ```APIDOC ## [DECORATOR] @bot.gateway.command ### Description Registers a function as a Gateway event handler. The decorated function receives a response object with event classification and parsed data. ### Usage ```python @bot.gateway.command def event_handler(resp): # Handle events ``` ### Parameters - **resp** (object) - Required - The response object passed to the handler, containing event classification and parsed data. ### Response Object Structure - **resp.event** - Event type checking (e.g., `resp.event.message`) - **resp.parsed** - Parsed event data (e.g., `resp.parsed.auto()`) - **resp.raw** - Raw Gateway response (direct access to Discord data) ``` -------------------------------- ### fetchMembers Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Fetches members from a guild using the gateway. Supports various fetching strategies, data retention controls, partial range fetching, and rate limiting management. ```APIDOC ## fetchMembers ### Description Fetches members from a guild using the gateway. Supports various fetching strategies, data retention controls, partial range fetching, and rate limiting management. ### Method Gateway Action ### Endpoint `bot.gateway.fetchMembers(guild_id, channel_id, ...)` ### Parameters - **guild_id** (string) - Required - The ID of the guild to fetch members from. - **channel_id** (string) - Required - The ID of the channel to use for fetching. - **method** (string or integer or array) - Optional - Fetching strategy. Can be `"overlap"` (default), `"no overlap"`, a custom multiplier (must be multiple of 100), or an array of multipliers. - **wait** (number or null) - Optional - Time to wait between requests to avoid rate limits. Set to `None` to disable rate limiting. - **keep** (string or array) - Optional - Controls data retention. Use `"all"` to keep all member properties, an array of property names to keep specific properties, or an empty array for minimal data. - **startIndex** (integer) - Optional - Start fetching from a specific index (useful for resuming interrupted fetches). - **stopIndex** (integer) - Optional - Stop fetching before a specific index. ### Request Example ```python bot.gateway.fetchMembers(guild_id, channel_id, method="overlap", wait=1) ``` ### Response Returns a list of member objects with the properties specified by the `keep` parameter. Available member properties: `['pending', 'deaf', 'hoisted_role', 'presence', 'joined_at', 'public_flags', 'username', 'avatar', 'discriminator', 'premium_since', 'roles', 'is_pending', 'mute', 'nick', 'bot', 'communication_disabled_until']`. ``` -------------------------------- ### Login Request Body Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.2-authentication JSON payload for the initial POST to /auth/login. Includes email, password, and optional fields like undelete, captcha_key, login_source, and gift_code_sku_id. ```json { "email": "user@example.com", "password": "password", "undelete": false, "captcha_key": null, "login_source": null, "gift_code_sku_id": null } ``` -------------------------------- ### bot.click() Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.1-button-and-slash-command-examples Triggers a button or menu interaction on a message. This method sends the interaction request to Discord. ```APIDOC ## bot.click() ### Description Triggers a button or menu interaction on a message. This method sends the interaction request to Discord. ### Method click ### Parameters - **authorID** (string) - Required - The ID of the message author (used for REST-based clicks). - **channelID** (string) - Required - The ID of the channel where the message is located. - **guildID** (string) - Optional - The ID of the guild where the message is located. - **messageID** (string) - Required - The ID of the message containing the button/menu. - **messageFlags** (number) - Required - The flags of the message. - **data** (object) - Required - The click data obtained from Buttoner.getButton() or Buttoner.getMenuSelection(). - **sessionID** (string) - Optional - The Gateway session ID (required for Gateway-integrated clicks). ### Request Example ```python bot.click( data["author"]["id"], channelID=data["channel_id"], guildID=guildID, messageID=data["id"], messageFlags=data["flags"], data=buts.getButton("First"), ) ``` ### Response - No response body is returned; the interaction is triggered asynchronously. ``` -------------------------------- ### Custom Multiplier Method for fetchMembers Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/7.3-member-fetching-tutorial Use a custom multiplier (must be a multiple of 100) or a list of multipliers to control fetch ranges. The first call fetches 150 members per request; the second uses variable multipliers per request. ```python # Custom multiplier (must be multiple of 100) bot.gateway.fetchMembers(guild_id, channel_id, method=150, wait=1) # Variable multipliers per request bot.gateway.fetchMembers(guild_id, channel_id, method=[100, 200, 300], wait=1) ``` -------------------------------- ### Request Wrapper Data Structure for Guild Member Search Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/6.1-extending-discum Constructs the data payload for a Gateway request to search guild members. Must be sent via `self.gatewayobject.send(data)` and includes the `op` field set to `REQUEST_GUILD_MEMBERS` and a `d` payload containing the guild IDs. ```python data = { "op": self.gatewayobject.OPCODE.REQUEST_GUILD_MEMBERS, "d": {"guild_id": guild_ids}, } ``` -------------------------------- ### Track online friends and send DM on presence update Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Maintains a list of online friends using session data and presence events. On presence_updated for a non-guild online user, adds the user and sends a DM via REST API. ```python @bot.gateway.command def presence_tracker(resp): if resp.event.ready_supplemental: # Initialize online friends list bot.usersOnline = list(bot.gateway.session.onlineFriendIDs) print(f"Tracking {len(bot.usersOnline)} online friends") if resp.event.presence_updated: data = resp.raw['d'] if "guild_id" not in data and data['status'] == 'online': user_id = data['user']['id'] if user_id not in bot.usersOnline: bot.usersOnline.append(user_id) # Send notification via REST API dm_channel = bot.createDM([user_id]) bot.sendMessage(dm_channel['id'], "Welcome back!") ``` -------------------------------- ### Send message and add reaction via REST API Source: https://deepwiki.com/Merubokkusu/Discord-S.C.U.M/2.3-basic-usage-patterns Synchronous REST API calls that immediately execute HTTP requests to Discord's API. Use sendMessage with a channel ID and message text, and addReaction with channel ID, message ID, and emoji. ```python # Direct API calls - synchronous execution bot.sendMessage("238323948859439", "Hello :)") bot.addReaction("238323948859439", "842574767584182273", "👍") ```