Last active
May 17, 2017 14:50
-
-
Save Proximyst/87a5befab6d3650a0b7dae4c22432876 to your computer and use it in GitHub Desktop.
dabbotbestbot - go
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 DabBotBestBot | |
import ( | |
"github.com/bwmarrin/discordgo" | |
"flag" | |
"fmt" | |
"strings" | |
"os" | |
"os/signal" | |
"syscall" | |
) | |
var ( | |
Token string | |
) | |
func init() { | |
flag.StringVar(&Token, "t", "", "token") | |
flag.Parse() | |
} | |
func main() { | |
bot, err := discordgo.New("Bot " + Token) | |
if err != nil { | |
fmt.Println("The discord bot encountered an error while creating: ", err) | |
return | |
} | |
bot.AddHandler(initialized) | |
bot.AddHandler(messageSent) | |
fmt.Println("The bot is now running. CTRL+C or other means of closing it will cancel the bots activity.") | |
channel := make(chan os.Signal, 1) | |
signal.Notify(channel, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) // Send all the signals to our channel | |
<-channel // wait for anything to happen | |
bot.Close() // Close the session and un-register events | |
} | |
func initialized(session *discordgo.Session, event *discordgo.Ready) { | |
session.UpdateStatus(0, "!!!DABBOT BEST BOT!!!") | |
} | |
func messageSent(session *discordgo.Session, event *discordgo.MessageCreate) { | |
if event.Author.ID == session.State.User.ID { | |
return // The bot itself sent the message. | |
} | |
if !strings.HasPrefix(event.Content, "!") { | |
return // Wasn't a command | |
} | |
session.ChannelMessageDelete(event.ChannelID, event.Message.ID) // ignores error cuz theres no perm checks | |
session.ChannelMessageSend(event.ChannelID, "!!!DABBOT BEST BOT!!!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment