Converting poll to a slash command

This commit is contained in:
Luke Robles 2022-10-11 08:39:18 -07:00
parent e19ac9fe25
commit 2bee710a77
2 changed files with 20 additions and 3 deletions

View File

@ -20,6 +20,12 @@ for cogfile in cogfiles:
bot.load_extension(cogfile)
@bot.slash_command(guild_ids=None, name="hello", description="Prints hello")
async def hello(ctx, name: str = None):
name = name or ctx.author.name
await ctx.respond(f"Hello {name}!")
@bot.event
async def on_ready():
print(f"{bot.user.name} has connected to Discord!")

View File

@ -1,13 +1,24 @@
import discord
from discord.ext import commands
from discord.commands import Option
class QuickPoll(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
async def poll(self, ctx, question, *options: str):
@commands.slash_command(
guild_ids=None,
pass_context=True,
description="Create a poll with up to 10 options. Separate your options with a space",
)
async def poll(
self,
ctx,
question,
options: Option(str, "poll options (separated by spaces)", required=True),
):
options = options.split()
if len(options) <= 1:
await ctx.send("You need more than one option to make a poll!")
return
@ -28,7 +39,7 @@ class QuickPoll(commands.Cog):
for reaction in reactions[: len(options)]:
await react_message.add_reaction(reaction)
embed.set_footer(text="Poll ID: {}".format(react_message.id))
await react_message.edit_message(embed=embed)
await react_message.edit(embed=embed)
@commands.command(pass_context=True)
async def tally(self, ctx, id=None):