Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

Discord.py voting command


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your command is forgetting to call the command, which is the double parenthesis, ()

Simply can be fixed by adding: client.command() to the top where it previously says without the parenthesis

It's better to include "None" in your message decorator, as it allows members to know they must pass a message through, otherwise it would not run the command.

I choose to optionally add some more functionality to your command, (only if you wish for use) and the option of sending it to a different channel, but I have tried this and should work. Hope this helps, change it to whatever you need.

@client.command()
async def poll(ctx, *, message=None):

        if message == None:
                await ctx.send(f'Cannot create a poll with no message!')
                return

        questions = [
            f"Which channel should your poll be sent to?"
        ]
        answers = []

        def check(m):
                return m.author == ctx.author and m.channel == ctx.channel

        for i in questions:
                await ctx.send(i)

                try:

                      msg = await client.wait_for('message', timeout=30.0, check=check)
                
                except asyncio.TimeoutError:
                        await ctx.send("Setup timed out, please be quicker next time!")
                        return
                else:
                        answers.append(msg.content)

        try:
                c_id = int(answers[0][2:-1])
        except:
                await ctx.send(
                    f"You didn't mention a channel properly, please format like {ctx.channel.mention} next time."
                )
                return

        channel = client.get_channel(c_id)


        embed = discord.Embed(title="Poll", description='{message}', colour=discord.Color.black())
        message = await channel.send(embed=embed )

        await message.add_reaction('??')
        await message.add_reaction('??')


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...