-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
49 lines (42 loc) · 889 Bytes
/
main.go
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
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"log"
"os"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
)
func main() {
// DiscordのBotトークンとログチャンネルを.envから取得
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file", err)
}
Token := os.Getenv("TOKEN")
logChannelID := os.Getenv("logChannelID")
// どのディレクトリをDiscordに出力するか引数で選択
sendFile := os.Args[1]
//discordと接続
discord, err := discordgo.New("Bot " + Token)
if err != nil {
log.Fatal(err)
}
err = discord.Open()
if err != nil {
log.Fatal(err)
}
defer discord.Close()
f, err := os.Open(sendFile)
if err != nil {
println(err)
}
defer f.Close()
data := &discordgo.MessageSend{
Files: []*discordgo.File{
{
Name: sendFile,
Reader: f,
},
},
}
discord.ChannelMessageSendComplex(logChannelID, data)
}