Created
March 7, 2019 21:44
-
-
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.
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
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