Google Cloud Platform Attachments
Warning
Discord does not offer any stability guarantees for this feature so it can break without notice.
Discord supports uploading attachments directly on their Google Cloud Platform. You can then send the same file multiple times without sending its content multiple times.
Uploading File to Google Cloud Platform
using NetCord;
using NetCord.Rest;
using RestClient client = new(new BotToken("Token from Discord Developer Portal"));
ulong channelId = 857933275112800266;
var bucketName = "file.txt";
// Creating Google Cloud Platform Storage Bucket
var buckets = await client.CreateGoogleCloudPlatformStorageBucketsAsync(channelId, [new(bucketName)]);
var bucket = buckets.First();
using (HttpContent fileContent = new StringContent("File content"))
using (HttpClient httpClient = new())
{
// Uploading file content
var response = await httpClient.PutAsync(bucket.UploadUrl, fileContent);
response.EnsureSuccessStatusCode();
}
var uploadFileName = bucket.UploadFileName;
Console.WriteLine(uploadFileName);
Sending Google Cloud Platform Attachment
using NetCord;
using NetCord.Rest;
using RestClient client = new(new BotToken("Token from Discord Developer Portal"));
ulong channelId = 864636357821726730; // Note that it doesn't need to be the same channel id as channel id used to upload
var fileName = "file.txt";
var uploadFileName = "cc7c13c1-a13d-4b3a-b978-e2c003466155/file.txt"; // It's returned when creating Google Cloud Platform Storage Bucket
await client.SendMessageAsync(channelId, new()
{
Attachments = [new GoogleCloudPlatformAttachmentProperties(fileName, uploadFileName)]
});