Last active
June 16, 2023 20:07
-
-
Save alexjyong/6aa1036c2234e32239798e6590f82f0a to your computer and use it in GitHub Desktop.
gist for my poll bot. too lazy to make a repo rn
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 discord | |
from discord.ext import commands | |
# Set up the bot prefix | |
prefix = "!" | |
# Create a bot instance with intents | |
intents = discord.Intents.all() | |
intents.typing = False # Disable typing event (optional) | |
intents.presences = False # Disable presence event (optional) | |
bot = commands.Bot(command_prefix=prefix, intents=intents) | |
# Event triggered when the bot is ready | |
@bot.event | |
async def on_ready(): | |
print(f"Logged in as {bot.user.name}") | |
# Command to start a poll | |
@bot.command() | |
async def poll(ctx, question=None, *options): | |
if question is None: | |
await ctx.send("Please provide a question for the poll. Command needs to be in format like so: '!poll \"question\" \"answer1\" \"answer2\" ' ") | |
return | |
if len(options) <= 1: | |
await ctx.send("Please provide at least 2 options for the poll. (e.g. '!poll \"What is your favorite color?\" \"Red\" \"Blue\" \"Green\"') ") | |
return | |
# Create the poll message | |
poll_message = f"**{question}**\n\n" | |
for i, option in enumerate(options): | |
poll_message += f"{i+1}. {option}\n" | |
# Send the poll message | |
poll_message += "\nReact to vote!" | |
poll = await ctx.send(poll_message) | |
# Add reactions to the poll message using number emojis | |
number_emoji_base = 0x0030 +1 | |
for i, option in enumerate(options): | |
emoji = chr(number_emoji_base + i) | |
await poll.add_reaction(f"{emoji}\u20e3") | |
# Run the bot | |
bot.run('TOKEN') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment