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
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
// MessageCreate is handlers of messageCreate event
|
||||
func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID && m.Author.Bot {
|
||||
return
|
||||
}
|
||||
|
||||
if m.Content == "!ping" {
|
||||
s.ChannelMessageSend(m.ChannelID, "Pong!")
|
||||
if strings.HasPrefix(m.Content, "머핀아 ") {
|
||||
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/bwmarrin/discordgo"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
token := os.Getenv("TOKEN")
|
||||
if err != nil {
|
||||
fmt.Println("[goMuffin] 봇의 설절파일을 불러올 수가 없어요.")
|
||||
log.Fatalln(err)
|
||||
}
|
||||
config := LoadConfig()
|
||||
|
||||
dg, err := discordgo.New("Bot " + token)
|
||||
dg, err := discordgo.New("Bot " + config.token)
|
||||
if err != nil {
|
||||
fmt.Println("[goMuffin] 봇의 세션을 만들수가 없어요.")
|
||||
log.Fatalln(err)
|
||||
|
@ -35,6 +29,5 @@ func main() {
|
|||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
<-sc
|
||||
|
||||
// Cleanly close down the Discord session.
|
||||
dg.Close()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue