【问题标题】:Reroll Giveaway command not responding when command run?命令运行时重新滚动赠品命令没有响应?
【发布时间】:2021-04-08 08:22:39
【问题描述】:

我正在尝试制作一个不和谐的赠品重投命令。 问题是,当命令运行时,它没有响应/重新滚动赠品。 我用相同的命令查看了多个站点,但所有站点都没有工作/对此进行了修复。 我还尝试不使用嵌入,看看这是否是代码的问题。 以下是重新滚动命令代码 - (如果需要赠品命令代码我可以提供)

    @client.command()
    @commands.has_permissions(kick_members=True)
    async def reroll(ctx, channel : discord.TextChannel, id_ : int):
        try:
            new_msg = await channel.fetch_message(id_)
        except:
            embed = discord.Embed(title="Command Error ⛔ - GameBot", description=f"**The Id Of A Channel Was Entered Incorrectly!** ????", color=0x992d22)
            await ctx.send(embed=embed)
            return
        
        users = await new_msg.reactions[0].users().flatten()
        users.pop(users.index(client.user))

        winner = random.choice(users)

        embed = discord.Embed(title="Giveaways ???? - GameBot", description=f"**Giveaway Has Been Rerolled!** \n \n**Winner -** \n`{winner.mention}`", color=0xe74c3c)
        await ctx.send(embed=embed)

以下是赠品命令代码-

@client.command()
    @commands.has_permissions(kick_members=True)
    async def giveaway(ctx):
        embed = discord.Embed(title="Giveaway Setup ???? - GameBot", description=f'**{ctx.author.mention} Giveaway Setup Is Now Starting... Please Answer These Questions Within 30 Seconds!**', color=0xe74c3c)
        await ctx.send(embed=embed)

        questions = ["**What Channel Should The Giveaway Be Hosted In?** `EX : #general` ????",
                    "**What Is The Duration Of The Giveaway?** `EX : S/M/H/D` ????",
                    "**What Is The Giveaway Prize?** `EX : Gift Card` ????"]

        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:
                embed = discord.Embed(title="Command Error ⛔ - GameBot", description=f"**Please Answer All Of The Questions In Time... Be Prepared!** ????", color=0x992d22)
                await ctx.send(embed=embed)
            else:
                answers.append(msg.content)
        
        try:
            c_id = int(answers[0][2:-1])
        except:
            embed = discord.Embed(title="Command Error ⛔ - GameBot", description=f"**Please Provide A Valid Channel For Me To Host The Giveaway In!** `EX : #general` ????", color=0x992d22)
            await ctx.send(embed=embed)
            return

        channel = client.get_channel(c_id)

        time = convert(answers[1])
        if time == -1:
            embed = discord.Embed(title="Command Error ⛔ - GameBot", description=f"**The Time Constraint You Answered With Was Not A Valid Unit!** `EX : S/M/H/D` ????", color=0x992d22)
            await ctx.send(embed=embed)
            return
        elif time == -2:
            embed = discord.Embed(title="Command Error ⛔ - GameBot", description=f"**The Time Must Include An Integer!** `EX : 1S, 1M, 1H, 1D` ????", color=0x992d22)
            await ctx.send(embed=embed)
            return

        prize = answers[2]

        embed = discord.Embed(title="Giveaway Setup ???? - GameBot", description=f'**Giveaway Channel -** \n`{channel.mention}` \n**Duration -** \n`{answers[1]}`', color=0xe74c3c)
        await ctx.send(embed=embed)


        givembed = discord.Embed(title="Giveaways ???? - GameBot", description=f'**Giveaway Prize/Description -** \n`{prize}`', color=0x2ecc71)

        givembed.add_field(name = "**Host -**", value=ctx.author.mention)

        givembed.set_footer(text = f"Ending {answers[1]} From Now! ????")

        my_msg = await channel.send(embed=givembed)


        await my_msg.add_reaction("????")


        await asyncio.sleep(time)


        new_msg = await channel.fetch_message(my_msg.id)


        users = await new_msg.reactions[0].users().flatten()
        users.pop(users.index(client.user))

        winner = random.choice(users)

        embed = discord.Embed(title="Giveaways ???? - GameBot", description=f"**Giveaway Has Ended!** \n \n**Winner -** \n`{winner.mention}` \n**Prize -** \n`{prize}`", color=0xe74c3c)
        await ctx.send(embed=embed)

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    几乎所有关于代码的内容都是正确的。但是,我猜您以错误/无效的方式请求users。您可以尝试以其他方式请求用户,这似乎是错误的来源。

    试试以下方法:

    users = [u for u in await new_msg.reactions[0].users().flatten() if u != client.user]
    
    winner = random.choice(users)
    

    完整的代码是:

    @client.command()
    @commands.has_permissions(kick_members=True)
    async def giveaway(ctx):
    # Giveaway code
    
    
    @client.command()
    @commands.has_permissions(kick_members=True)
    async def reroll(ctx, channel: discord.TextChannel, id_: int):
        try:
            new_msg = await channel.fetch_message(id_)
        except:
            embed = discord.Embed(title="Command Error ⛔ - GameBot",
                                  description=f"**The Id Of A Channel Was Entered Incorrectly!** ?", color=0x992d22)
            await ctx.send(embed=embed)
            return
    
        user_list = [u for u in await new_msg.reactions[0].users().flatten() if u != client.user]
    
        winner = random.choice(user_list)
    
        embed = discord.Embed(title="Giveaways ? - GameBot",
                              description=f"**Giveaway Has Been Rerolled!** \n \n**Winner -** \n`{winner.mention}`",
                              color=0xe74c3c)
        await ctx.send(embed=embed)
    

    【讨论】:

    • 你提供的代码不起作用,我检查了我是否写错了命令,但我没有。不过感谢您的帮助!如果我有超过 15 个代表,我会投票赞成。 (终端也没有给我错误)
    • 再检查一次,我用message而不是new_msg。我提供的代码与您的代码相结合对我来说效果很好。
    • 我不知道那可能只是我愚蠢并且在不和谐中写错了命令大声笑。但感谢所有的帮助!我一定要试试新代码。
    • 我提供的完整代码也不起作用?我得到一个输出。还要注意正确的缩进。
    • 我是否应该将代码发送给赠品命令,也许我需要更新其中的某些内容才能工作?
    猜你喜欢
    • 2020-03-17
    • 2021-03-20
    • 2021-04-02
    • 2021-04-18
    • 2021-05-02
    • 2021-06-02
    • 2021-03-10
    • 2013-03-25
    • 1970-01-01
    相关资源
    最近更新 更多