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(BaseClient): Fall back to userAgentAppendix #10113

Merged
merged 1 commit into from
Feb 2, 2024
Merged

Conversation

Jiralite
Copy link
Member

@Jiralite Jiralite commented Feb 2, 2024

Please describe the changes this PR makes and why it should be merged:
We're currently getting an undefined string in our user agent strings (if an appendix is not specified):

Request {
  headersTimeout: undefined,
  bodyTimeout: undefined,
  throwOnError: false,
  method: 'GET',
  abort: null,
  body: null,
  completed: false,
  aborted: false,
  upgrade: null,
  path: '/api/v10/gateway/bot',
  origin: 'https://discord.com',
  idempotent: true,
  blocking: false,
  reset: null,
  host: null,
  contentLength: null,
  contentType: null,
  headers: 'User-Agent: DiscordBot (https://discord.js.org, 2.2.0) undefined\r\n' +
    'Authorization: Bot [REDACTED]\r\n',
  expectContinue: false,
  servername: null,
  [Symbol(handler)]: RequestHandler {
    responseHeaders: null,
    opaque: null,
    callback: [Function (anonymous)],
    res: null,
    abort: null,
    body: null,
    trailers: {},
    context: null,
    onInfo: null,
    throwOnError: undefined,
    highWaterMark: undefined,
    [Symbol(async_id_symbol)]: 92,
    [Symbol(trigger_async_id_symbol)]: 0,
    [Symbol(kSignal)]: AbortSignal { aborted: false },
    [Symbol(kListener)]: [Function (anonymous)]
  }
}

This happens because userAgentAppendix may be explicitly undefined here:

rest: {
...defaultOptions.rest,
...options.rest,
userAgentAppendix: options.rest?.userAgentAppendix
? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`
: undefined,
},

Eventually, it reaches this point:

this.options = { ...DefaultRestOptions, ...options };

The explicit undefined value is overwriting the default value.

This is a fault of discord.js as it is not possible to do new REST({ userAgentAppendix: undefined }); due to exact optional property types being set. I've thus opted to fall back to the default value which has been tested even with the past bug #9421 and works fine.

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 Feb 2, 2024

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

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Feb 2, 2024 3:17pm
discord-js-guide ⬜️ Ignored (Inspect) Feb 2, 2024 3:17pm

@Jiralite Jiralite changed the title fix(BaseClient): explicit undefined for userAgentAppendix fix(BaseClient): Conditionally add userAgentAppendix Feb 2, 2024
@Jiralite Jiralite changed the title fix(BaseClient): Conditionally add userAgentAppendix fix(BaseClient): Fall back to userAgentAppendix Feb 2, 2024
@kodiakhq kodiakhq bot merged commit b16647e into main Feb 2, 2024
7 checks passed
@kodiakhq kodiakhq bot deleted the fix/no-rest-undefined branch February 2, 2024 16:32
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.

4 participants