# Upgrade discord.js in a TypeScript Bot

Yes. An agent moves discord.js and its @discordjs packages to the newest 14 release, clears the deprecations lint reports, type-checks, tests and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/upgrade-discord-js/discord-js/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the versions from the lockfile, not the range. In a bot built on KevinNovak/Discord-Bot-TypeScript-Template, `package.json` asks for `discord.js` at `^14.22.1` and `@discordjs/rest` at `^2.6.0`, and `package-lock.json` resolves `discord.js` to 14.22.1 with `discord-api-types` 0.38.21, `@discordjs/builders` 1.11.3 and `@discordjs/ws` 1.2.3 under it. `discord.js-rate-limiter` is pinned at exactly `1.3.2`. It looks up the registry's `latest` tag for each, reads the release notes between the locked version and that one, and writes down which packages have to move together: `discord.js` declares its own range for `@discordjs/rest`, `^2.6.0` in the locked release, and the bot depends on the same package directly.

It records a baseline before changing anything: `npm ci`, `npm run build`, `npm run lint` and `npm test` on the default branch, with the output kept. `npm run build` compiles with `tsconfig.json`, which excludes `tests`, so the agent also runs `npx tsc --project tsconfig.test.json`. That is the only command that type-checks the 831-line `tests/builders/discord-builders.ts`, where every mocked `User`, `Guild` and interaction is typed against the library and where a changed signature shows up first.

Then it upgrades and reads what the tools say. `eslint.config.mjs` sets `@typescript-eslint/no-deprecated` to `warn`, so `npm run lint` after the upgrade lists every call the new typings mark deprecated, by file and line. One is known in advance: the six entries in `src/commands/metadata.ts` each set `dm_permission`, which `discord-api-types` already marks deprecated in favour of `contexts`. The agent replaces a deprecated call only where the replacement is a like-for-like change it can cover with a test, and lists the others. `src/utils/interaction-utils.ts` already passes `flags: MessageFlags.Ephemeral` and calls the `fetchReply()` method after `reply`, not the deprecated `fetchReply` option, so that file should need nothing.

It also checks the floor. The package's `engines` asks for Node 18 or later and so does `discord.js`, while the `Dockerfile` starts `FROM node:16`. The agent does not build the image, because the sandbox has no Docker, but it reports the mismatch and, if the request allows, moves the base image to the Node version the sandbox ran the suite on. It cannot log a bot in: there is no token in the sandbox, and it says that the gateway connection, sharding and command registration were not exercised.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "codex",
  "input": "Upgrade discord.js in this bot to the newest release the registry tags latest, staying on the current major. Read package.json, package-lock.json, tsconfig.json, tsconfig.test.json, eslint.config.mjs, vitest.config.ts, the Dockerfile and the README first. Record a baseline on the default branch: npm ci, npm run build, npx tsc --project tsconfig.test.json, npm run lint and npm test, keeping the output. Read the release notes between the locked discord.js version and the target. Upgrade discord.js and @discordjs/rest together so only one copy of each @discordjs package is installed, and confirm that with npm ls. Leave discord.js-rate-limiter and every unrelated dependency where they are. Run the same five commands again. For each deprecation that lint now reports, replace the call only when the replacement is equivalent and a test covers it, and list the rest with file and line. Report whether the Dockerfile's Node version satisfies the engines field of this package and of discord.js, and change the base image only if it does not. Do not start the bot or register commands. Open a pull request with the old and new versions as a table, the before and after output of each command, the deprecations fixed and the ones left, and what was not exercised.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `package.json` and `package-lock.json`, and only the source lines a deprecation forced. Its description opens with a table: each package that moved, the locked version before and after, and whether it moved because you asked or because `discord.js` requires it. Under that are the five commands, before and after. A reader can see that the lint warnings on the default branch and on the branch differ only by the deprecations named, and that `npm ls` shows one copy of `@discordjs/rest`.

It is explicit about what a green suite does not prove. The tests build interactions from mocks, so they show that the bot's own code still compiles and behaves against the new typings; they say nothing about the gateway. The description lists what to check with a real token before deploying: that `npm run commands:view` still matches, that the bot reaches `clientReady`, and that a deferred hidden reply still arrives hidden.

A reviewer reads the lockfile diff for packages that moved without a reason in the table, then the deprecation list. The `dm_permission` change deserves a real look, because `contexts` describes where a command appears and the six commands all set `dm_permission: true` today; the agent states the `contexts` value it believes is equivalent and leaves that file alone unless you confirm.

## Run it on every Monday morning

Minor releases of discord.js follow Discord's API changes, so falling a few behind means the typings stop describing what the gateway sends. Create an automation in the Project that holds the repository with a `schedule` trigger whose `cron` is `0 9 * * 1` in your `timezone`, and this page's request as its prompt with one more sentence: if the locked version is already the newest, end with one line saying so and open nothing. The automation's own max runs per hour applies to it.

The repository's caret range already lets `npm install` pick up a newer 14 release, and that is the reason to run it on a schedule with the checks attached: the range moves silently on a fresh install, while the lockfile and the proof move together in one pull request. A dependency bot's pull request cannot start this run, since a `github` trigger never fires for bot senders.

## Why run it on Rush?

A discord.js bump looks like a one-line change and is usually merged as one. What makes it safe is the dull part: a baseline to compare against, a type-check of the test builders that `npm run build` skips, and a read of the lint output for new deprecations. On a laptop those get run once, after the upgrade, with nothing to compare to. The agent runs them on both sides in a clean sandbox and keeps both outputs, so the pull request shows a difference and not just a result.

It also runs when nobody is thinking about the bot. A bot that works gets no attention until Discord changes something, and by then the upgrade spans many releases. One small pull request a week, each with its commands and output in the run's transcript, keeps every step reviewable. If you run several bots, each repository gets its own run and its own lockfile diff.

## Frequently asked questions

### Will it move the bot to discord.js 15?

No. The request stays on the current major, and when this page was written the registry's `latest` tag for `discord.js` was a 14 release with 15 published only under `dev`. A major upgrade changes builders, events and REST handling and belongs in its own run with its own prompt.

### Why upgrade @discordjs/rest separately from discord.js?

Because the bot imports `REST` from `@discordjs/rest` directly in `src/start-bot.ts` and `discord.js` depends on the same package through its own range. If the two ranges stop overlapping, two copies install, and an `instanceof` check on an error from one fails against the class from the other. The agent moves both and checks with `npm ls`.

### Can it test against the real Discord API?

Not without a token, and the request does not give it one. If you want that, store a token for a test application as a secret in the Project and say in the prompt which guild to use. The default run stops at compile, lint and the mocked suite, and says so.

### What happens to discord.js-rate-limiter?

Nothing. It is pinned at `1.3.2`, its peer range accepts any `discord.js` from 12 up, and the request tells the agent to leave it. The pull request notes the pin so you can decide about it separately.

### Does it fix the lint warnings that were already there?

No. The baseline exists so that old warnings are not mistaken for new ones. Only deprecations that appear because of the upgrade are in scope, and each is either replaced with a test behind it or listed.

## More discord.js jobs

- [Write Vitest Tests for a discord.js Bot](https://getrush.ai/run/write-vitest-tests/discord-js/)
- [Write a Dockerfile for a discord.js Bot](https://getrush.ai/run/add-dockerfile/discord-js/)
- [Add Modals to a discord.js Bot](https://getrush.ai/run/add-modals/discord-js/)

## More jobs like this: Upgrade dependencies weekly

- [Upgrade a Docusaurus 2 Site to Docusaurus 3](https://getrush.ai/run/upgrade-docusaurus/docusaurus/)
- [Upgrade Drizzle ORM and Drizzle Kit](https://getrush.ai/run/upgrade-drizzle-orm/drizzle/)
- [Upgrade Electron and npm Dependencies in an Electron App](https://getrush.ai/run/upgrade-electron/electron/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
