Converting poll to a slash command
This commit is contained in:
parent
ca3f22daea
commit
0986ce64c5
@ -20,6 +20,12 @@ for cogfile in cogfiles:
|
|||||||
bot.load_extension(cogfile)
|
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
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f"{bot.user.name} has connected to Discord!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
@ -1,13 +1,24 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord.commands import Option
|
||||||
|
|
||||||
|
|
||||||
class QuickPoll(commands.Cog):
|
class QuickPoll(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.slash_command(
|
||||||
async def poll(self, ctx, question, *options: str):
|
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:
|
if len(options) <= 1:
|
||||||
await ctx.send("You need more than one option to make a poll!")
|
await ctx.send("You need more than one option to make a poll!")
|
||||||
return
|
return
|
||||||
@ -28,7 +39,7 @@ class QuickPoll(commands.Cog):
|
|||||||
for reaction in reactions[: len(options)]:
|
for reaction in reactions[: len(options)]:
|
||||||
await react_message.add_reaction(reaction)
|
await react_message.add_reaction(reaction)
|
||||||
embed.set_footer(text="Poll ID: {}".format(react_message.id))
|
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)
|
@commands.command(pass_context=True)
|
||||||
async def tally(self, ctx, id=None):
|
async def tally(self, ctx, id=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user