Skip to content

Instantly share code, notes, and snippets.

@Proximyst
Last active May 17, 2017 14:50
Show Gist options
  • Save Proximyst/87a5befab6d3650a0b7dae4c22432876 to your computer and use it in GitHub Desktop.
Save Proximyst/87a5befab6d3650a0b7dae4c22432876 to your computer and use it in GitHub Desktop.
dabbotbestbot - go
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