Discord Poll Bot

 import os
import discord
from discord.ext import commands
from collections import defaultdict
import asyncio
import re

# Retrieve the Discord bot token from the environment variables
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')

intents = discord.Intents.default()
intents.messages = True
intents.reactions = True
bot = commands.Bot(command_prefix='/', intents=intents)

class Poll:
    def __init__(self, question, options, duration=24):
        self.question = question + " 🤔"
        self.options = options
        self.votes = defaultdict(int)
        self.message = None
        self.duration = duration * 3600  # Convert hours to seconds
        self.poll_task = None

About this template

This Discord bot allows users to create polls with custom questions, options, and durations. Users can interact with the bot using the "/poll" command to create polls, which are then presented with reaction emojis for voting. The bot tallies votes in real-time and announces the winning option when the poll closes. It is designed to be user-friendly, providing help messages and feedback on command usage.

Introduction to the Discord Poll Bot Template

Welcome to the Discord Poll Bot template! This template allows you to create a Discord bot that can facilitate polls within your Discord server. Users can interact with the bot using the "/poll" command to create polls with custom questions, options, and durations. The bot will then present the poll with reaction emojis for voting and tally the votes in real-time, announcing the winning option when the poll closes.

Getting Started with the Template

To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.

Initial Setup: Adding Environment Secrets

Before you can test and use the Discord Poll Bot, you need to set up an environment secret for the Discord bot token. Here's how to acquire and set up your Discord bot token:

  • Go to the Discord Developer Portal and create a new application.
  • Inside your application, navigate to the "Bot" tab and create a new bot.
  • Under the bot settings, you will find the token. Copy this token as you will need it for the next step.
  • In the Lazy Builder interface, go to the Environment Secrets tab.
  • Create a new secret with the key 'DISCORD_BOT_TOKEN' and paste the token you copied as the value.

Test: Pressing the Test Button

Once you have set up your environment secret, you can press the "Test" button to begin the deployment of your Discord Poll Bot. The Lazy CLI will handle the deployment process, and you won't need to provide any additional input at this stage.

Using the App

After deployment, your Discord Poll Bot will be live on your Discord server. To create a poll, use the "/poll" command followed by the question, duration, and options. For example:


/poll question={Do you like pizza?} duration={1} options={Yes, No, Maybe}

Users can vote by reacting to the poll message with the corresponding emojis. The bot will automatically close the poll after the specified duration and announce the results.

Integrating the App

If you wish to integrate the Discord Poll Bot with other tools or services, you may need to provide the bot's server link or API endpoints. Since this template is designed to work within Discord, no additional external integration steps are required unless you plan to extend the bot's functionality beyond the provided template.

Remember, this bot is designed to work within the Lazy platform, so there's no need to worry about local environments or operating systems. Enjoy creating engaging polls for your Discord community!

Category
Technology
Last published
July 26, 2024

More templates like this

SecureUserAuthenticator

Develop a secure User Authentication system for users to register, log in, and manage their profiles, laying the foundation for user-specific data management and permissions in the CMS.

Laravel
Python
Flask
Javascript

Simple Multiplayer Telegram game

This app is a simple frontend for a game where users can upvote and downvote the most popular word in their country, learn about the flags of other countries, and view what other people voted for on a leaderboard.

Telegram
Python
Javascript

MP3ify: Youtube to MP3 Converter

A web application that allows users to download YouTube videos from URLs and provides the option to convert them to MP3 format.

Python
Flask
Home
/
Discord Poll Bot