Discord Poll Bot
Hi i am trying to make a poll bot but ive encountered a problem here is the code ignore the other commands other than + poll import discord import os import requests import json im
Solution 1:
I would not use on_message
events for that but instead use a command.
You can do something like this:
import discord
from discord.ext import commands
@client.command()asyncdefpoll(ctx, *, text: str):
poll = await ctx.send(f"{text}")
await poll.add_reaction("✅")
await poll.add_reaction("❌")
Here we have text
as a str
so you can add as many text as you want.
If you want to compare it after 24 hours you would also have to build in a cooldown saver if the bot restarts, otherwise we could go with await asyncio.sleep(TimeAmount)
If you want to check the result with a command we could go for this:
from discord.utils import get
import discord
from discord.ext import commands
@client.command()asyncdefresults(ctx, channel: discord.TextChannel, msgID: int):
msg = await channel.fetch_message(msgID)
reaction = get(msg.reactions, emoji='✅')
count1 = reaction.count # Count the one reaction
reaction2 = get(msg.reactions, emoji="❌")
count2 = reaction2.count # Count the second reactionawait ctx.send(f"✅**: {count1 - 1}** and ❌**: {count2 - 1}**") # -1 is used to exclude the bot
The usage of the command would be: results #channel MSGID
.
Be aware that fetch
is an API call and could cause a ratelimit.
Post a Comment for "Discord Poll Bot"