Created
February 11, 2020 07:53
-
-
Save vascoferreira25/60f13253e5370decf3245d773026c59c to your computer and use it in GitHub Desktop.
Discord bot written in Clojurescript
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
(ns core | |
(:require ["discord.js" :as Discord])) | |
;; Setup | |
(def admin-token "token") | |
(def general-chat-id "chat-id") | |
(def client | |
"New instance of client, notice the last `.`" | |
(Discord/Client.)) | |
;; Send login message and set activity | |
(defn login-message [] | |
(println "The bot is online.") | |
(.setActivity (.-user client) "Doin' random stuff") | |
(-> client | |
(.-channels) | |
(.get general-chat-id) | |
(.send "How do you do me hearties."))) | |
;; Handle messages | |
(defn message-handler [message] | |
;; Ignore message if author is the client | |
(if-not (= (.-author message) (.-user client)) | |
(cond | |
;; Mentioned | |
(-> message (.isMentioned (.-user client))) | |
(-> message | |
(.-channel) | |
(.send "Its a message for me")) | |
;; Specific words | |
(-> message (.-content) (.startsWith "!bot")) | |
(-> message | |
(.-channel) | |
(.send (str (-> message (.-author) (.toString)) | |
", hohoho who's the bot?!"))) | |
;; Everything else | |
:else (-> message | |
(.-channel) | |
(.send "Just reading..."))))) | |
(defn -main [] | |
(.on client "ready" login-message) | |
(.on client "message" message-handler) | |
(.login client admin-token)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment