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

Wrong encoding in file preview message with Buffer #6823

Open
viruspowaa opened this issue Apr 26, 2024 · 2 comments
Open

Wrong encoding in file preview message with Buffer #6823

viruspowaa opened this issue Apr 26, 2024 · 2 comments
Labels
bug message components click click click click click click click synced Synced to internal tracker

Comments

@viruspowaa
Copy link

Description

Hello,

I try to send file from Buffer, but I have an issue with encoding. My file content is encode in 'utf-8' but Discord message preview is not.
When Discord unfurls the attachment as a preview, it looks like it's content sniffing. In this case, it appears to be text/plain; charset=ISO-8859-1.

bot.ts

import { AttachmentBuilder, Client, Events, GatewayIntentBits, TextChannel } from "discord.js";
import { Buffer } from "node:buffer";

const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

client.once(Events.ClientReady, () => {
  // 🤖 Discord bot is ready! 🤖
});

client.on(Events.GuildAvailable, async (guild) => {
  const bufTest = Buffer.from("Récapitulatif", "utf-8");
  console.log("bufTest :>> ", bufTest);
  console.log("bufTest value :>> ", bufTest.toString());
  const channel = guild.channels.cache.get("<<CHANNEL_ID>>") as TextChannel;
  const bTst = new AttachmentBuilder(bufTest, {
    name: "tst.log",
    description: "Test",
  });
  channel.send({ content: "test 2", files: [bTst] });
});

client.login("<<TOKEN>>");

Console result

bufTest :>>  <Buffer 52 c3 a9 63 61 70 69 74 75 6c 61 74 69 66>
bufTest value :>>  Récapitulatif

Discord result

image

Steps to Reproduce

Run code of 'bot.ts' previously write

Expected Behavior

I want that Discord show the file in the good encoding

Current Behavior

Wrong encoding in preview

Screenshots/Videos

image

Client and System Information

Versions

"discord.js": "^14.12.1",
"dotenv": "^16.4.5",
"@types/node": "^20.11.20",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3"

gateway intents

Guilds, GuildMessages

@viruspowaa viruspowaa added bug message components click click click click click click click labels Apr 26, 2024
@afgiel
Copy link
Contributor

afgiel commented Apr 26, 2024

do you have a repro that does not involve using a library? (eg curl)

@afgiel afgiel added the synced Synced to internal tracker label Apr 26, 2024
@viruspowaa
Copy link
Author

viruspowaa commented Apr 27, 2024

No ! I have not ! But I can try to make an example with it !
But how do it ? How can I use curl to send a message with buffered file ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug message components click click click click click click click synced Synced to internal tracker
Projects
None yet
Development

No branches or pull requests

2 participants