feat: Add prefix
This commit is contained in:
parent
7fba76a935
commit
65820fc23a
2 changed files with 12 additions and 11 deletions
|
@ -1,15 +1,23 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MessageCreate is handlers of messageCreate event
|
||||||
func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
if m.Author.ID == s.State.User.ID && m.Author.Bot {
|
if m.Author.ID == s.State.User.ID && m.Author.Bot {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Content == "!ping" {
|
if strings.HasPrefix(m.Content, "머핀아 ") {
|
||||||
s.ChannelMessageSend(m.ChannelID, "Pong!")
|
content := strings.TrimPrefix(m.Content, "머핀아 ")
|
||||||
|
if content == "안녕" {
|
||||||
|
s.ChannelMessageSend(m.ChannelID, "안녕")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
main.go
11
main.go
|
@ -9,18 +9,12 @@ import (
|
||||||
|
|
||||||
"github.com/Muffin-laboratory/goMuffin/handler"
|
"github.com/Muffin-laboratory/goMuffin/handler"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := godotenv.Load()
|
config := LoadConfig()
|
||||||
token := os.Getenv("TOKEN")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("[goMuffin] 봇의 설절파일을 불러올 수가 없어요.")
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dg, err := discordgo.New("Bot " + token)
|
dg, err := discordgo.New("Bot " + config.token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("[goMuffin] 봇의 세션을 만들수가 없어요.")
|
fmt.Println("[goMuffin] 봇의 세션을 만들수가 없어요.")
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
@ -35,6 +29,5 @@ func main() {
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
<-sc
|
<-sc
|
||||||
|
|
||||||
// Cleanly close down the Discord session.
|
|
||||||
dg.Close()
|
dg.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue