Skip to content

Instantly share code, notes, and snippets.

@JohnnyJayJay
Created March 7, 2019 21:44
Show Gist options
  • Save JohnnyJayJay/44053f54f6c90ee0f989b9ad52774163 to your computer and use it in GitHub Desktop.
Save JohnnyJayJay/44053f54f6c90ee0f989b9ad52774163 to your computer and use it in GitHub Desktop.
Bot that sends a random cat pic if you ping it. Needs kotlin and khttp and jda as dependencies.
import net.dv8tion.jda.core.JDABuilder
import net.dv8tion.jda.core.events.GuildMessageReceivedEvent
import khttp.get
import org.json.JSONObject
fun main(args: Array<String>) {
JDABuilder("bot token").addEventListener(event -> {
if (event is GuildMessageReceivedEvent && event.guild.selfMember in event.message.mentionedMembers) {
val response = get("https://api.thecatapi.com/v1/images/search", headers = mapOf("x-api-key" to "key"))
val cat = (response.jsonArray[0] as JSONObject).getString("url")
event.channel.sendMessage(cat).queue()
}
}).build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment