Skip to content

Instantly share code, notes, and snippets.

@vascoferreira25
Created February 11, 2020 07:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vascoferreira25/60f13253e5370decf3245d773026c59c to your computer and use it in GitHub Desktop.
Save vascoferreira25/60f13253e5370decf3245d773026c59c to your computer and use it in GitHub Desktop.
Discord bot written in Clojurescript
(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