man oscar The manual Chat

Discord

Setting up a Discord bot: developer portal, Message Content intent, invite link, slash commands.

MANUAL / CHAT 9 / 29

Oscar connects to Discord as a bot: the Gateway (a websocket) for messages and button presses, the REST API for everything it sends. No public address or open port is needed.

Set it up

  1. Create the application. Open the Discord developer portal, New Application, give it a name.
  2. Get the token. In the application, Bot → Reset Token → copy it into $OSCAR_HOME/credentials.env (mode 0600):
    text
    DISCORD_BOT_TOKEN=MTk4...
    On the same page you can turn Public Bot off, so only you can add it to servers.
  3. Turn on the Message Content intent. Still under Bot, in Privileged Gateway Intents, enable Message Content Intent and save. Oscar asks for it by default; without it Discord closes the connection (the log says "Discord refused a privileged intent (close 4014)"). If you only use direct messages and @mentions, you can instead set DISCORD_MESSAGE_CONTENT=false: Discord still sends the text of those, but free-response channels need the intent.
  4. Say who may talk to Oscar. In Discord, turn on User Settings → Advanced → Developer Mode, then right-click your name → Copy User ID:
    text
    DISCORD_ALLOWED_USERS=284102345871466496
    (comma-separated for several; also discord_allowed_users in config.toml). A username works too (yuri; such a user is known as @yuri), and DISCORD_ALLOWED_ROLES lets every member of a role in. Or let the bot find you: oscar discord owner --add, then send the bot a direct message (oscar setup offers the same).
  5. Invite the bot. oscar discord probe prints the bot's name, the gateway it will use, whether the Message Content intent is switched on in the portal (it asks Discord), who is allowed, and an invite link with the bot and applications.commands scopes (the second for slash commands) and the permissions Oscar uses: View Channels, Send Messages, Create Public Threads, Send Messages in Threads, Read Message History, Add Reactions and Attach Files. Open the link and pick your server.
  6. Run it: oscar discord serve (Discord alone) or oscar gateway serve (every configured platform; see Chat gateways, also for running it as a service).
  7. Talk to it: send the bot a direct message (open it from the member list of a server you share), or mention it in a channel: @Oscar what changed in the last release?

Servers and channels

In server channels Oscar answers only when mentioned (a reply that pings it counts). A mention in a channel starts a thread from your message and the answer goes there; in a thread Oscar started, no mention is needed. Not in free-response channels, in threads, for replies, or in discord_no_thread_channels. With a mention, the channel's messages since Oscar last spoke there (up to 20) go along as context, so it knows what was said before. Messages from people not on the allowed list are ignored in channels and told no in direct messages. Threads count as their parent channel for the lists below. The model sees who wrote each message ([Crew|284102345871466496] …, the server nickname or display name) and the channel's name.

Variable (config key) Meaning
DISCORD_REQUIRE_MENTION (discord_require_mention) false: answer every message in server channels (default true); !mention on|off|default changes one channel
DISCORD_FREE_RESPONSE_CHANNELS (discord_free_response_channels) channel ids where every message is for Oscar
DISCORD_ALLOWED_CHANNELS (discord_allowed_channels) when set, the only server channels Oscar answers in (direct messages are not affected)
DISCORD_IGNORED_CHANNELS (discord_ignored_channels) channels never answered in, even when mentioned
DISCORD_ALLOWED_ROLES (discord_allowed_roles) role ids whose members are allowed like listed users
DISCORD_AUTO_THREAD (discord_auto_thread) false: answer a mention in the channel itself (default true)
DISCORD_NO_THREAD_CHANNELS (discord_no_thread_channels) channels answered in place even with threads on
DISCORD_HISTORY_BACKFILL (discord_history_backfill), DISCORD_HISTORY_BACKFILL_LIMIT earlier messages as context with a mention (default on, 20)
DISCORD_REPLY_TO_MODE (discord_reply_to_mode) a reply points at your message: first message (default), all, off
DISCORD_ALLOWED_MENTIONS (discord_allowed_mentions) who a reply may ping: users, roles, everyone (comma-separated); default nobody
DISCORD_ALLOW_BOTS (discord_allow_bots) messages from other bots and webhooks: off (default), mentions, all — the bot must be allowed too

Channel ids: with Developer Mode on, right-click a channel → Copy Channel ID.

A thread is a conversation of its own (replies stay in it); in a server channel each person has a conversation of their own unless discord_group_sessions = "shared" (see rooms shared by several people). A channel's own settings go in [rooms."discord:<channel id>"]; a thread is a channel, so it takes its own table (require_mention = false there makes it free-response).

Slash commands

Oscar's commands are also native slash commands: /status, /new, /steer use the staging database, the admin ones (/pair, /voice, …). Each takes the rest of the line as one optional text. They are registered in each server as the bot joins it, so changes show at once (discord_slash_commands = "on", the default); "global" registers them for the whole application, which also offers them in direct messages but may take Discord a while to show; "off" registers none. A command is answered at once with "Oscar is thinking…", which the reply then replaces. Typed ! commands keep working. Registering needs the applications.commands scope: a bot invited without it logs why and works with ! commands only (invite it again with the link from oscar discord probe).

The list also offers your skills, most used first, as many as fit in Discord's 100 commands: /pdf summarise the attachment runs the pdf skill for that message. When the skills change (!reload-skills, an accepted skill, or a change made elsewhere, looked for every five minutes) the commands are registered again wherever they were, only when the list changed, and at most once a minute (rate limits are waited out).

A forum channel works as a target for scheduled results, send_message and !handoff: a message to it opens a post named after its first line (the rest of a long text goes into the post), and a handed-over conversation opens a post of its own. Files (send_file, MEDIA: attachments of a reply) go into the post the reply's text just opened; a file sent on its own opens a post named after the file.

What it looks like

  • Commands are typed with ! (!new, !status, !stop; see Chat gateways), or used as slash commands.
  • Replies are Discord Markdown, split under the 2000-character limit, and ping nobody unless discord_allowed_mentions says so: @everyone, roles and users in a reply stay plain text (status lines, prompts and direct messages never ping).
  • Approvals and questions come with buttons. A press from someone not on the list gets a reply only they can see; after a decision the buttons go and the decision is added to the message.
  • While working, Oscar reacts 👀, shows "typing…" and edits a quiet activity message listing each call with a short preview (tool activity); then ✅ or ❌. A message sent during a turn gets ⚡, ⏳ or ⏩. DISCORD_REACTIONS=false turns reactions off, DISCORD_TYPING=false typing; DISCORD_PROGRESS (off, new, all, verbose) or !verbose sets how much the activity message shows.
  • Voice messages, pictures, files, and spoken or picture replies: see Voice, pictures and files. A bot may upload 10 MB in a server without boosts; set DISCORD_UPLOAD_LIMIT_MB (config discord_upload_limit_mb) when your server takes more (50 with level 2 boosts, 100 with level 3). Attachments are fetched only from Discord's own servers, up to 50 MB. Videos and GIFs play in place (the file name carries the right extension).
  • After a restart Oscar resumes its Gateway session, so Discord sends what arrived meanwhile; nothing is answered twice.

Other settings

Variable Meaning
DISCORD_ALLOW_ALL_USERS=true answer everyone (careful)
DISCORD_SLASH_COMMANDS (discord_slash_commands) on (per server, default), global or off
DISCORD_PAIRING=on (discord_pairing) strangers who write privately get a pairing code
DISCORD_ADMINS, DISCORD_APPROVERS (discord_admins, discord_approvers) user ids: who may use the admin commands, who may answer approvals (roles)
DISCORD_API_URL, DISCORD_GATEWAY_URL another REST base or Gateway URL (proxies, tests)