我正在尝试发出赠品命令,但无法选择获胜者并将获胜者发送嵌入。它发送“新赠品开始!”嵌入很好并对其做出反应,但它不会发送获胜者嵌入说赠品已经结束以及谁赢得了它。我也没有错误。我的代码是
@commands.command()
@commands.has_role('Giveaways')
async def gcreate(self, ctx, time=None, *, prize=None):
if time == None:
await ctx.send(f'{ctx.author.mention}, you need to give the duration! `Example: 1m, 1h, 7d`')
return
if prize == None:
await ctx.send(f'{ctx.author.mention}, you need to give the prize!')
return
embed=discord.Embed(title='New Giveaway Started!', color=0x1CDEA3)
embed.add_field(name='Prize:', value=f'{prize}', inline=False)
time_convert = {"s":1, "m":60, "h":3600, "d":86400}
gawtime = int(time[0]) * time_convert[time[-1]]
embed.add_field(name='Duration:', value=f'{time}', inline=False)
embed.add_field(name='From:', value=f'{ctx.author.mention}', inline=False)
embed.set_footer(text=f'{ctx.guild.name}')
embed.set_thumbnail(url=ctx.author.avatar_url)
embed.timestamp = datetime.datetime.utcnow()
gaw_msg = await ctx.send(embed=embed)
await gaw_msg.add_reaction("?")
await asyncio.sleep(gawtime)
new_msg = await ctx.channel.fetch_message(gaw_msg.id)
user_list = [u for u in await new_msg.reactions[0].users().flatten() if u != self.bot.user]
# After we have the list, we can check if any users reacted
if len(user_list) == 0:
await ctx.send("No one reacted.")
else:
winner = random.choice(user_list)
winnerembed=discord.Embed(title='Giveaway Ended', description=f'**{winner}** won the giveaway for\n***{prize}*** !', color=0x1CDEA3)
winnerembed.set_footer(text=f'{ctx.guild.name}')
winnerembed.timestamp = datetime.datetime.utcnow()
winnerembed.set_thumbnail(url=winner.avatar_url)
await ctx.send(embed=winnerembed)
await ctx.send(winner.mention)
任何帮助将不胜感激。
答案 0 :(得分:1)
所以从评论中我假设现在一切正常,除了时间。这是由于您的 gawtime
转换器中的一个小错误造成的。
试试这个功能:
gawtime = int(time[:-1]) * time_convert[time[-1]]
time[0]
始终为 1,因此 10 秒为一秒,time[-1]
为 m
,因此将转换为 10 秒。