Lazo Lab Sign up

App 8: Build a Discord Bot / Build a Discord bot

Lesson 8 of 10

A trivia game command

Combine what you learned in the quiz app with Discord buttons: ask a question and let people click an answer.

Key points

  • discord.ui.View holds buttons
  • Each button has a callback
  • Reply privately with ephemeral=True
class Quiz(discord.ui.View):
    @discord.ui.button(label="443")
    async def right(self, interaction, button):
        await interaction.response.send_message("Correct! 🎉", ephemeral=True)

    @discord.ui.button(label="80")
    async def wrong(self, interaction, button):
        await interaction.response.send_message("Nope, try again!", ephemeral=True)

@tree.command(name="quiz", description="Port quiz")
async def quiz(interaction: discord.Interaction):
    await interaction.response.send_message("Which port does HTTPS use?", view=Quiz())

Your turn

Turn your quiz questions from App 1 into a /quiz command.

Watch a video on thisOpens YouTube search results for “A trivia game command” in a new tab

Quiz · +10 XP

What does ephemeral=True do?

Log in to save progress and earn XP.