Created
October 5, 2020 02:57
-
-
Save jaydonnell/d7586591001d5adaaa58f30d9a6388e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"strings" | |
"github.com/andersfylling/disgord" | |
) | |
func printMessage(session disgord.Session, evt *disgord.MessageCreate) { | |
fmt.Println(evt.Message.Author, " said:") | |
fmt.Println(evt.Message.Content) | |
fmt.Println(evt.Message.Author.ID) | |
fmt.Println() | |
if strings.Contains(evt.Message.Content, "ping") && !evt.Message.Author.Bot { | |
//_, _ = evt.Message.Reply(context.Background(), session, "pong") | |
_, _, _ = evt.Message.Author.SendMsgString(evt.Ctx, session, "dm pong") | |
} | |
} | |
func sendDM(session disgord.Session, evt *disgord.MessageCreate) { | |
fmt.Println(evt) | |
} | |
func main() { | |
client := disgord.New(disgord.Config{ | |
BotToken: "<token goes here>", | |
}) | |
// connect, and stay connected until a system interrupt takes place | |
defer client.StayConnectedUntilInterrupted(context.Background()) | |
// create a handler and bind it to new message events | |
// handlers/listener are run in sequence if you register more than one | |
// so you should not need to worry about locking your objects unless you do any | |
// parallel computing with said objects | |
client.On(disgord.EvtMessageCreate, printMessage) | |
client.On(disgord.EvtTypingStart, sendDM) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment