Skip to content

bug: @sapphire/string-store may generate invalid custom ids #886

@Jiralite

Description

@Jiralite

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

@sapphire/string-store may generate invalid ids. The following is an example:

enum CustomId {
  User = 0,
}

const store = new SchemaStore().add(
  new Schema(CustomId.User).string("username").snowflake("userId")
);

store.serialize(CustomId.User, { username: "Terra", userId: "1071822091814441000" });

This serialises to: ��敔牲⡡А莅��

Creating a message in a channel will result in an internal server error and responding to an interaction with this custom id will immediately result in an unknown interaction.

Steps To Reproduce

Using discord.js 15.0.0-dev.1745021572-92e07c8f7:

import { Schema, SchemaStore } from "@sapphire/string-store";
import {
  Client,
  TextChannel,
  ComponentType,
  ButtonStyle,
  GatewayIntentBits,
  Events,
} from "discord.js";

const client = new Client({ intents: GatewayIntentBits.Guilds });

enum CustomId {
  User = 0,
}

const store = new SchemaStore().add(
  new Schema(CustomId.User).string("username").snowflake("userId")
);

client.on(Events.ClientReady, async () => {
  (client.channels.cache.get(CHANNEL_ID) as TextChannel).send({
    components: [
      {
        type: ComponentType.ActionRow,
        components: [
          {
            type: ComponentType.Button,
            style: ButtonStyle.Primary,
            label: "test",
            customId: store
              .serialize(CustomId.User, {
                username: "Terra",
                userId: "1071822091814441000",
              })
              .toString(),
          },
        ],
      },
    ],
  });
});

void client.login(DISCORD_TOKEN);

Expected behavior

The message should be created or the interaction should be responded to.

Screenshots

No response

Additional context

No response

System Info

System:
  OS: macOS 15.4.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 370.16 MB / 36.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.13.1 - /opt/homebrew/opt/node@22/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 10.9.2 - /opt/homebrew/opt/node@22/bin/npm
  pnpm: 9.12.3 - /opt/homebrew/bin/pnpm
  bun: 1.2.10 - ~/.bun/bin/bun
Browsers:
  Safari: 18.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions