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
Incorrect MIME Type in Content_Type for Certain Filename Extensions #6785
Comments
Hey @AWATV! Can you provide us with the exact requests you're sending and responses you're getting? Thanks! |
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.DirectMessages,
],
});
const token = '...';
const guildId = '1195451831149658225';
const channelId = '1196091248201695262';
client.once('ready', async () => {
console.log('Bot is ready!');
try {
const guild = await client.guilds.fetch(guildId);
if (!guild) throw new Error('Guild not found');
const channel = guild.channels.cache.get(channelId);
if (!channel) throw new Error('Channel not found');
const messages = await channel.messages.fetch({ limit: 1 });
const lastMessage = messages.first();
if (lastMessage) {
console.log('Last Message Attachments:', lastMessage.attachments);
} else {
console.log('No messages found in the channel');
}
} catch (error) {
console.error('Error:', error);
}
client.destroy();
});
client.login(token); Bot is ready!
Last Message Attachments: Collection(2) [Map] {
'1225338377726070794' => Attachment {
attachment: 'https://cdn.discordapp.com/attachments/1196091248201695262/1225338377726070794/somename.mp3.gz?ex=6620c44a&is=660e4f4a&hm=399aee161711361af26937cb41bd37d19b487bbb2a6658addc0567c6fe07c422&',
name: 'somename.mp3.gz',
id: '1225338377726070794',
size: 5455565,
url: 'https://cdn.discordapp.com/attachments/1196091248201695262/1225338377726070794/somename.mp3.gz?ex=6620c44a&is=660e4f4a&hm=399aee161711361af26937cb41bd37d19b487bbb2a6658addc0567c6fe07c422&',
proxyURL: 'https://media.discordapp.net/attachments/1196091248201695262/1225338377726070794/somename.mp3.gz?ex=6620c44a&is=660e4f4a&hm=399aee161711361af26937cb41bd37d19b487bbb2a6658addc0567c6fe07c422&',
height: null,
width: null,
contentType: 'audio/mpeg',
description: null,
ephemeral: false,
duration: null,
waveform: null,
flags: AttachmentFlagsBitField { bitfield: 0 }
},
'1225338378195828806' => Attachment {
attachment: 'https://cdn.discordapp.com/attachments/1196091248201695262/1225338378195828806/somename.mp3?ex=6620c44b&is=660e4f4b&hm=72396422a788b37340a4f599dc2b3aafd4f1c4850b4682975c856a37b7368d4c&',
name: 'somename.mp3',
id: '1225338378195828806',
size: 5469184,
url: 'https://cdn.discordapp.com/attachments/1196091248201695262/1225338378195828806/somename.mp3?ex=6620c44b&is=660e4f4b&hm=72396422a788b37340a4f599dc2b3aafd4f1c4850b4682975c856a37b7368d4c&',
proxyURL: 'https://media.discordapp.net/attachments/1196091248201695262/1225338378195828806/somename.mp3?ex=6620c44b&is=660e4f4b&hm=72396422a788b37340a4f599dc2b3aafd4f1c4850b4682975c856a37b7368d4c&',
height: null,
width: null,
contentType: 'audio/mpeg',
description: null,
ephemeral: false,
duration: null,
waveform: null,
flags: AttachmentFlagsBitField { bitfield: 0 }
}
} |
Decided to test this myself. Was curious if it was some weird thing with like it just pulling the first file extension. Here's my bot code:
I created a text file with the content:
I duplicated that file 14 times and added/change the extension: Here are the results:
Based on this line:
It doesn't know what a According to Mimetype it should be registering On a side note, I wanted to test behavior for other "non-existent" file extensions
|
Description
When retrieving message attachments via the Discord API, an issue arises with the determination of the MIME type for certain filename extensions. Specifically, when an attachment is named "
somename.mp3.gz
" and its content is a gzip-compressed file, the API incorrectly returns the MIME type asaudio/mpeg
instead of the expectedapplication/x-gzip
. This discrepancy between the expected and actual MIME types could lead to misinterpretation of file content by applications or bots relying on accurate MIME type detection.This bug affects developers and users who utilize the Discord API to handle message attachments, particularly those dealing with compressed files. Proper MIME type identification is essential for ensuring correct processing and handling of attachments within applications or bots integrated with Discord.
Steps to Reproduce
Send a message with an attachment named "
somename.mp3.gz
" to a Discord server or channel.Retrieve the message using the Discord API, specifically focusing on accessing the attachment object.
Check the
content_type
property of the attachment object.Expected Behavior
The
content_type
property for an attachment named "somename.mp3.gz
" should returnapplication/x-gzip
, indicating that the file is a gzip-compressed file.Current Behavior
The
content_type
property for an attachment named "somename.mp3.gz
" returnsaudio/mpeg
, which is incorrect for a gzip-compressed file. This behavior is inconsistent with the expected MIME type.Screenshots/Videos
No response
Client and System Information
Node.js modules:
API version: V14
The text was updated successfully, but these errors were encountered: