← Back to Functions
šŸ“Š

Poll Bot

Discord Bot

3 of 4

Discord Bot Exercise 3: Poll Bot

Build a poll creator for your Discord server! Users give a question and options, and your bot formats a beautiful poll message.


Your Task

Write two functions that work together to create formatted polls.

Function 1: format_option(index, text)

  • Takes a number (0, 1, 2...) and the option text
  • Returns a string with an emoji number and the text
  • Use this list of emoji numbers: ["1ļøāƒ£", "2ļøāƒ£", "3ļøāƒ£", "4ļøāƒ£", "5ļøāƒ£"]
  • Example: format_option(0, "Pizza") → "1ļøāƒ£ Pizza"

Function 2: create_poll(question, options)

  • Takes a question string and a list of option strings
  • Uses a loop and calls format_option() for each option
  • Returns a complete formatted poll string

The poll should look like:

šŸ“Š POLL: What should we play?
━━━━━━━━━━━━━━━━━━━━
1ļøāƒ£ Minecraft
2ļøāƒ£ Roblox
3ļøāƒ£ Fortnite

Vote by reacting below!

Starter Code

EMOJIS = ["1ļøāƒ£", "2ļøāƒ£", "3ļøāƒ£", "4ļøāƒ£", "5ļøāƒ£"] def format_option(index, text): # Return the emoji + text for one option pass def create_poll(question, options): # Build the full poll string # Start with the header, add each formatted option, end with footer pass # Test your functions: print(format_option(0, "Pizza")) # Output: 1ļøāƒ£ Pizza print(format_option(2, "Sushi")) # Output: 3ļøāƒ£ Sushi print("---") poll1 = create_poll("What should we play?", ["Minecraft", "Roblox", "Fortnite"]) print(poll1) print("===") poll2 = create_poll("Best programming language?", ["Python", "JavaScript", "C++", "Scratch"]) print(poll2)

Expected Output

1ļøāƒ£ Pizza
3ļøāƒ£ Sushi
---
šŸ“Š POLL: What should we play?
━━━━━━━━━━━━━━━━━━━━
1ļøāƒ£ Minecraft
2ļøāƒ£ Roblox
3ļøāƒ£ Fortnite

Vote by reacting below!
===
šŸ“Š POLL: Best programming language?
━━━━━━━━━━━━━━━━━━━━
1ļøāƒ£ Python
2ļøāƒ£ JavaScript
3ļøāƒ£ C++
4ļøāƒ£ Scratch

Vote by reacting below!

Hints

Hint 1 — format_option

Use the EMOJIS list with the index:

def format_option(index, text): return f"{EMOJIS[index]} {text}"
Hint 2 — Building the poll string

Build the string piece by piece. You can use \n for new lines:

result = f"šŸ“Š POLL: {question}\n" result += "━━━━━━━━━━━━━━━━━━━━\n" # Add each option... result += "\nVote by reacting below!"
Hint 3 — Looping with index

Use enumerate() or range(len(...)) to get both the index and the item:

for i, option in enumerate(options): result += format_option(i, option) + "\n"
Solution
EMOJIS = ["1ļøāƒ£", "2ļøāƒ£", "3ļøāƒ£", "4ļøāƒ£", "5ļøāƒ£"] def format_option(index, text): return f"{EMOJIS[index]} {text}" def create_poll(question, options): result = f"šŸ“Š POLL: {question}\n" result += "━━━━━━━━━━━━━━━━━━━━\n" for i, option in enumerate(options): result += format_option(i, option) + "\n" result += "\nVote by reacting below!" return result

Topics Practiced

  • Functions calling functions — create_poll calls format_option
  • Lists — storing options and emoji characters
  • Indexing — accessing list items by position
  • Loops with enumerate — getting both index and value
  • String building — concatenating with += and \n
  • Return values — building and returning a complex string

Try it — then send to Discord!

Write your code below. Click Run to test locally, then click Send to Discord to have the bot post your output to the server!

Code: Poll Bot

Loading Python runtime...
Python ...Discord Bot Mode
Loading...
Output
Click "Run" to execute your code...