Skip to content

feat(format): spell Discord's message markup once - #12

Merged
mikield merged 1 commit into
masterfrom
feat/message-formatting
Sep 2, 2026
Merged

mikield merged 1 commit into
masterfrom
feat/message-formatting

Conversation

@mikield

@mikield mikield commented Sep 2, 2026

Copy link
Copy Markdown
Member

Mentions, timestamps and custom emoji get assembled by hand wherever a message is built, and one assembled slightly wrong renders as literal text rather than failing — the bot shows <@123> to its users and nothing in the logs says why. Format holds the shapes so they are written correctly in one place.

Format::user($userId);                                  // <@254766810296090626>
Format::channel($channelId);                            // <#979052732218503179>
Format::command('voice room limit', $commandId);        // </voice room limit:12345>
Format::emoji('apex', $emojiId, animated: true);        // <a:apex:12345>
Format::timestamp($when, TimestampStyle::Relative);     // <t:1618928400:R>
Format::codeBlock($sql, 'sql');

Two things worth pointing out:

  • Timestamp styles are an enum, not the raw letter. Nothing about 'R' says "2 months ago" at a call site, and the letters are case-sensitive in a way that is easy to get wrong (d and D are different formats). The default matches Discord's own default when no style is given.
  • timestamp() takes int|DateTimeInterface. Seconds because that is what the API takes, and a native date because that is what most callers have. It deliberately knows nothing about any particular datetime library.

This came out of a bot that had grown its own copy of exactly these five helpers.

🤖 Generated with Claude Code

Mentions, timestamps and custom emoji are assembled by hand wherever a
message is built, and one assembled slightly wrong renders as literal text
rather than failing: the bot shows `<@123>` to its users and nothing says
why. Format holds the shapes so they are written correctly in one place.

Timestamp styles are an enum rather than the single letter the API takes,
since nothing about 'R' says "2 months ago" at a call site.
@mikield
mikield merged commit 4512390 into master Sep 2, 2026
4 checks passed
@mikield
mikield deleted the feat/message-formatting branch September 2, 2026 01:23
github-actions Bot pushed a commit that referenced this pull request Sep 2, 2026
## [1.2.0](v1.1.0...v1.2.0) (2026-09-02)

### Features

* **format:** spell Discord's message markup once ([#12](#12)) ([4512390](4512390))

### Bug Fixes

* **rest:** modify a channel with PATCH rather than POST ([#11](#11)) ([e8f47bf](e8f47bf))
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant