我试图发出一个赠品命令,但我在让它选择一个获胜者并发送获胜者时遇到了问题。它发送“新的赠品开始!”嵌入很好,并对其作出反应,但它不会发送获奖者嵌入说赠品结束了,谁赢得了它。我也没有犯错误。我的代码是
@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)
任何帮助都将不胜感激
因此,从评论中,我假设除了时间之外,现在一切都正常。这是由于
gawtime
转换器中有一个小错误造成的试试这个功能:
time[0]
始终为1,因此10秒为1秒,time[-1]
为m
,因此将转换为10秒相关问题 更多 >
编程相关推荐