discord-cli

    Discord REST CLI for coding agents: read guilds, channels and messages, send messages, and call raw routes with a bot token. Built on gaato/discord.

    discord
    cli
    skill
    agent
    Download zip
    Author
    Version
    0.2.4
    License
    Apache-2.0
    Last updated
    14 days ago
    Downloads
    224

    #gaato/discord-cli

    Use Discord's bot REST API from a shell. Read the bot's guilds, channels and recent messages, send a message or a reply, or call any other REST route, and get JSON you can pipe into another program. It is designed to be run by coding agents as well as by people, and comes with an agent skill. It is built on gaato/discord.

    Unofficial, and not affiliated with Discord.

    #Install

    Run the prebuilt Wasm executable with MoonBit's moonx, which downloads the latest release and runs it on moonrun. No native compiler or Node.js is needed. Help works without a token:

    moonx gaato/discord-cli --help

    #Run

    Put a bot token in the DISCORD_TOKEN environment variable, then:

    moonx gaato/discord-cli me moonx gaato/discord-cli guilds moonx gaato/discord-cli channels 123456789012345678 moonx gaato/discord-cli messages 234567890123456789 --limit 10 moonx gaato/discord-cli send 234567890123456789 'Hello' moonx gaato/discord-cli api GET /users/@me

    To post the output of another command as a reply:

    printf '%s\n' 'Build complete.' | moonx gaato/discord-cli send 234567890123456789 --stdin --reply-to 345678901234567890

    OptionApplies toMeaning
    --token TOKENAll commandsOverrides DISCORD_TOKEN. Prefer the environment, so the token does not appear in process listings.
    --help, -hAll commandsUsage text
    --versionRootVersion text
    --limit N, -n Nmessages CHANNEL_IDDefault 50. Larger limits are paginated.
    --before ID / --after IDmessages CHANNEL_IDExclusive cursors. Use one or the other.
    --stdinsend CHANNEL_ID [text...]Read the message from standard input (UTF-8) instead of the arguments
    --reply-to IDsend CHANNEL_ID [text...]Reply to a message
    --body JSON, -d JSONapi METHOD PATHJSON body. The path is relative to /api/v10.

    IDs are unsigned 64-bit decimal strings. Keep them as strings in scripts, since many JSON tools lose precision on numbers that large. Messages are sorted newest first. guilds fetches every page.

    #Output and exit codes

    Each successful data command prints one pretty-printed JSON document on stdout. Errors go to stderr as error: ....

    Exit codeMeaning
    0Success, or help
    1A Discord API, network or other runtime failure
    2Invalid arguments, a missing token, or an empty message

    So an empty list is distinguishable from a failed request.

    #Tokens and writes

    DISCORD_TOKEN must be a bot token, and the bot needs Discord permissions for what it reads or posts. send and modifying api calls act as the bot, and other people see the result.

    #Restricted host access

    An optional moonrun policy allows only the token and Discord over HTTPS, and denies filesystem access and process spawning. Save this as discord-policy.json:

    { "env": { "from_host": ["DISCORD_TOKEN"] }, "net": { "connect": ["discord.com:443"] } }

    moonx --experimental-policy discord-policy.json gaato/discord-cli me

    --stdin still reads standard input, and shell redirection opens files outside Wasm. The policy flag is experimental in moonx.

    #Targets

    The executable runs on moonrun, which provides its networking. Browser, WASI and wasm-gc runtimes are not supported. It also builds for native.

    #Agent skill

    The skill describes each command's output fields, when posting is appropriate, and how to handle rate limits.

    #License

    Apache-2.0