You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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";constclient=newClient({intents: [GatewayIntentBits.Guilds,GatewayIntentBits.GuildMessages],});client.once(Events.ClientReady,()=>{// 🤖 Discord bot is ready! 🤖});client.on(Events.GuildAvailable,async(guild)=>{constbufTest=Buffer.from("Récapitulatif","utf-8");console.log("bufTest :>> ",bufTest);console.log("bufTest value :>> ",bufTest.toString());constchannel=guild.channels.cache.get("<<CHANNEL_ID>>")asTextChannel;constbTst=newAttachmentBuilder(bufTest,{name: "tst.log",description: "Test",});channel.send({content: "test 2",files: [bTst]});});client.login("<<TOKEN>>");
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
Console result
Discord result
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
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
The text was updated successfully, but these errors were encountered: