diff --git a/main.go b/main.go index 59fa43b..b0512e5 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "image/png" + "io" "os" "time" @@ -46,37 +47,18 @@ func SendScreenshots(discord *discordgo.Session, channelId string, sleepDuration panic(err) } - file, err := os.Create(screenshot_path) + imageReader, imageWriter := io.Pipe() + go func() { + err = png.Encode(imageWriter, new_image) - if err != nil { - panic(err) - } + if err != nil { + panic(err) + } - err = png.Encode(file, new_image) + imageWriter.Close() + }() - if err != nil { - panic(err) - } - - err = file.Close() - - if err != nil { - panic(err) - } - - file, err = os.Open(screenshot_path) - - if err != nil { - panic(err) - } - - _, err = discord.ChannelFileSend(channelId, screenshot_path, file) - - if err != nil { - panic(err) - } - - err = file.Close() + _, err = discord.ChannelFileSend(channelId, screenshot_path, imageReader) if err != nil { panic(err)