Skip to content

Non-ASCII Filenames for Attachments Are Lost When Uploaded via Discord.js Bot Command #11302

@chasekafei

Description

@chasekafei

Which package is this bug report for?

discord.js

Issue description

Issue Summary: When a file attachment with a Chinese or other non-ASCII filename is uploaded via a Discord.js bot command, the retrieved name property for the attachment only retains ASCII characters; any non-ASCII (e.g. Chinese) characters are lost. This affects filenames such as "测试文件.jpg" or "Test测试.png" which become "Test.png" after upload.

Root Cause: The problem appears to originate from the basename function in packages/discord.js/src/util/Util.js (lines 397-400), which relies on Node.js's path.parse() and fails to preserve non-ASCII filename characters. This impacts all filenames containing Unicode characters and is directly visible in the bot-generated message attachments.

Code sample

// Simplified bot upload code
const attachment = new AttachmentBuilder(file);
// filename: "测试文件test.json"
// After sending: attachment.name === "test.json" (should be "测试文件test.json")

// Problematic code (Util.js):
function basename(path, ext) {
  const res = parse(path);
  return ext && res.ext.startsWith(ext) ? res.name : res.base.split('?')[0];
}
// Reference: https://github.com/discordjs/discord.js/blob/02fc101069aed994f7ee4579d114706047025ddd/packages/discord.js/src/util/Util.js#L397-L400

Versions

  • discord.js 14.24.2 (npm ls discord.js)
  • Node.js 24.11.0 (node --version)
  • TypeScript 5.9.3 (npm ls typescript)
  • OS: macOS Ventura 13.3.1

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable, No Partials

Which gateway intents are you subscribing to?

Not applicable, No Intents

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions