首页 > 解决方案 > 赠品命令时间 discord.py

问题描述

嘿伙计们,我需要帮助来制作一个以天/小时/分钟/秒显示时间的赠品命令现在我只能在赠品消息中以秒为单位显示时间我找到了一些方法以天/小时/命令中的分钟/秒,但不是机器人发送的消息。

我希望这是有道理的,如果没有我很抱歉

这是我的代码:

@bot.command(aliases=["gcreate"])
async def gstart(ctx, gtime,*, prize):
    if ctx.message.author.guild_permissions.manage_messages:
        time=convert(gtime)
        gembed=discord.Embed(title=f"<a:giveaway:828219055017951292> {prize}", description=f"⏳Time Left : {time} seconds\nHosted by : {ctx.author.mention}\nReact with <a:Tada:812191920238886922> to participate", color=0xFF5733)
        msg=await ctx.send(f"<a:Gift:828220390551453777> **GIVEAWAY** <a:Gift:828220390551453777>", embed=gembed)
        await msg.add_reaction("<a:Tada:812191920238886922>")
        while time:
            await asyncio.sleep(1)
            time-=1
            gembed.description=f"⏳Time Left : {time} seconds\nHosted by : {ctx.author.mention}\nReact with <a:Tada:812191920238886922> to participate"
            await msg.edit(embed=gembed)
        new_msg=await ctx.channel.fetch_message(msg.id)
        users=await new_msg.reactions[0].users().flatten()
        users.pop(users.index(bot.user))
        winner = random.choice(users)
        gembed.description=f"Winner : {winner.mention}\nHosted by : {ctx.author.mention}"
        await msg.edit(content=f"<a:Gift:828220390551453777> **GIVEAWAY ENDED** <a:Gift:828220390551453777>", embed=gembed)
        await ctx.send(f"Congratulations! {winner.mention} you won the giveaway of `{prize}`\nDm {ctx.author.mention} for your Rewards!")
    else:
        await ctx.send(f"Sorry {ctx.author.mention} but you do not have enough perms to use this command\n**__PERMS NEEDED__** <a:arrow_r:825382670514389072> Manage Messages")
@gstart.error
async def on_command_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(f"{ctx.author.mention} Try again in this format:\n""`[!gstart | !gcreate] {time[s|m|h|d]} {prize}`")

提前致谢

标签: pythondiscorddiscord.py

解决方案


推荐阅读