-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUploadBot.swift
More file actions
37 lines (33 loc) · 1.48 KB
/
FileUploadBot.swift
File metadata and controls
37 lines (33 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
import SwiftDisc
@main
struct FileUploadBot {
static func main() async {
let token = ProcessInfo.processInfo.environment["DISCORD_BOT_TOKEN"] ?? ""
let client = DiscordClient(token: token, configuration: .init(maxUploadBytes: 150 * 1024 * 1024)) // override guardrail if needed
client.onReady = { ready in
print("Logged in as: \(ready.user.username)")
}
// Example usage: send a file with optional embed
Task {
do {
// Replace with a real channel ID and a real file path in your environment
let channel: ChannelID = "000000000000000000"
let fileURL = URL(fileURLWithPath: "./README.md")
let data = try Data(contentsOf: fileURL)
let attachment = FileAttachment(
filename: fileURL.lastPathComponent,
data: data,
description: "Sample readme upload",
contentType: "text/markdown"
)
let embed = Embed(title: "Uploaded README", description: "File attached via SwiftDisc")
_ = try await client.sendMessageWithFiles(channelId: channel, content: "Here is the file", embeds: [embed], files: [attachment])
} catch {
print("Upload failed: \(error)")
}
}
try? await client.loginAndConnect(intents: [.guilds])
for await _ in client.events { _ = () }
}
}