initial commit
This commit is contained in:
79
main.go
Normal file
79
main.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var (
|
||||
Token string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&Token, "t", "", "Bot Token")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
session, err := discordgo.New("Bot " + Token)
|
||||
if err != nil {
|
||||
fmt.Println("error creating Discord session,", err)
|
||||
return
|
||||
}
|
||||
|
||||
session.AddHandler(messageCreate)
|
||||
|
||||
session.Identify.Intents = discordgo.IntentsGuildMessages
|
||||
|
||||
err = session.Open()
|
||||
if err != nil {
|
||||
fmt.Println("error opening connection,", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Bot is now running. Press CTRL-C to exit.")
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
<-sc
|
||||
|
||||
session.Close()
|
||||
}
|
||||
|
||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
fmt.Println(m.Content)
|
||||
if m.Content != "ping" {
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := s.UserChannelCreate(m.Author.ID)
|
||||
if err != nil {
|
||||
|
||||
fmt.Println("error creating channel:", err)
|
||||
s.ChannelMessageSend(
|
||||
m.ChannelID,
|
||||
"Something went wrong while sending the DM!",
|
||||
)
|
||||
return
|
||||
}
|
||||
_, err = s.ChannelMessageSend(channel.ID, "Pong!")
|
||||
|
||||
if err != nil {
|
||||
|
||||
fmt.Println("error sending DM message:", err)
|
||||
s.ChannelMessageSend(
|
||||
m.ChannelID,
|
||||
"Failed to send you a DM. "+
|
||||
"Did you disable DM in your privacy settings?",
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user