python - 赠品命令时间 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}`")
提前致谢
解决方案
推荐阅读
- c# - 是否可以从存储过程返回多个结果集?
- python - 如何修复我的程序不重复或完全删除我的“信息”列表的内容
- assembly - 确定目的地(寄存器名称或地址)和值
- css - 无法使用 .htaccess 中的 RewriteRule 访问文件
- r - 从R中的随机系统发育树制作0/1字符矩阵?
- python - 如何在 Python 中基于正则表达式拆分字符串
- apache-spark - 如果我将服务器上的所有可用内核分配给 spark 集群会发生什么
- jquery - Wordpress:在 ajax 生成的 div 上执行 JQuery
- date - 当我在 SAS 中计算新变量时,为什么我的值会发生偏移?
- python - 欧拉计划 #23 - 非丰富的总和