Warning
Work in progress. Not for general consumption. Contains chemicals known to the State of California to cause cancer and birth defects or other reproductive harm.[1]
Write Discord bots while leveraging the Typelevel ecosystem.
This example sends an embed with a button component that lets users increment the value displayed. The embed displays who performed the last three increments, and the updates are debounced to only occur every 3 seconds at most.
def counter[F[_]] = Cmd:
for
increment = Button[F]("+1")
msg <- replyEmbed(embed { title("0") }, components = List(increment))
_ <- increment.clicks(in = msg)
.interactTap { deferEdit } // immediately respond to the interaction…
.buffer(1)
.zipWithIndex
.map { case (given Interaction[F], count) =>
(count, s"$count. Clicked by **${invoker.mention}**!")
}
.sliding(3)
.debounce(3.seconds) // …but limit updates to a max of once every 3s
.evalMap { lastThreeClicks =>
val (latestCount, _) = lastThreeClicks.last.get
val summary = lastThreeClicks.map(_._2).mkString_("\n")
msg.edit(embed {
title(s"$latestCount".refineUnsafe)
description(summary.refineUnsafe)
})
}
.runFor(5.minutes)
yield msg