Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Message): Ensure channel is defined for clean content #10681

Merged
merged 2 commits into from
Jan 4, 2025

Conversation

Jiralite
Copy link
Member

@Jiralite Jiralite commented Jan 2, 2025

Please describe the changes this PR makes and why it should be merged:
channel may be null and thus when passing to cleanContent(), a crash will occur on valid types. This is reproducible in 2 (known) ways:

  1. Calling cleanContent on a forwarded message from a guild one is not in
  2. Calling cleanContent on a interaction's response message from a guild one is not in

Stack trace:

TypeError: Cannot read properties of null (reading 'client')
    at /Users/jiralite/Documents/GitHub/Soulobby/Soulobby/node_modules/.pnpm/[email protected]_patch_hash=uqmtazwjzsnpehwi2ldoqezswq/node_modules/discord.js/src/util/Util.js:389:44
    at [Symbol.replace] (<anonymous>)
    at String.replaceAll (<anonymous>)
    at cleanContent (/Users/jiralite/Documents/GitHub/Soulobby/Soulobby/node_modules/.pnpm/[email protected]_patch_hash=uqmtazwjzsnpehwi2ldoqezswq/node_modules/discord.js/src/util/Util.js:362:14)
    at get cleanContent (/Users/jiralite/Documents/GitHub/Soulobby/Soulobby/node_modules/.pnpm/[email protected]_patch_hash=uqmtazwjzsnpehwi2ldoqezswq/node_modules/discord.js/src/structures/Message.js:594:36)
    at Soulobby.fire (/Users/jiralite/Documents/GitHub/Soulobby/Soulobby/source/events/interaction-create.ts:119:80)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
Emitted 'error' event on Soulobby instance at:
    at emitUnhandledRejectionOrErr (node:events:407:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:92:21)

In both cases, a message is constructed with a channel id that is not cached, so that will result in null being sent to the cleanContent(). This will resolve #10679—seems they're calling .toJSON() somewhere to achieve this or cleanContent directly.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Jan 4, 2025 5:17pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Jan 4, 2025 5:17pm

@kodiakhq kodiakhq bot merged commit 1986c2d into main Jan 4, 2025
8 checks passed
@kodiakhq kodiakhq bot deleted the fix/uncached-clean-content branch January 4, 2025 17:19
Jiralite added a commit that referenced this pull request Jan 4, 2025
fix(Message): ensure channel is defined for clean content

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Throw an error on a specific message forwarding (external guild)
4 participants