[英]Getting error - 'int' object has no attribute 'time'
我正在尝试为我的机器人制作一个赠品命令,但每次我尝试运行该命令时都会收到错误消息
'int' object has no attribute 'time'
我的赠品命令代码
@client.command(description="Starts a giveaway.")
@has_permissions(manage_messages=True)
async def gstart(ctx, time: int, winners: int, *, prize: str):
global users, new_msg
try:
em = discord.Embed(
title=f"<a:fun:1052215771738165269> {prize} <a:fun:1052215771738165269>",
color=discord.Colour.random()
)
timestamp = time.time() + time
em.set_footer(text=f"Started by {ctx.author}")
em.add_field(name=f"** **", value=f"**Ends at**: <t:{int(timestamp)}:f> or <t:{int(timestamp)}:R> \n **Prize**: {prize} \n **Hosted by**: {ctx.author.mention}", inline=False)
my_msg = await ctx.send(embed=em)
await my_msg.add_reaction("🎉")
await asyncio.sleep(time)
new_msg = await ctx.channel.fetch_message(my_msg.id)
for i in range(winners):
users = [user async for user in new_msg.reactions[0].users()]
users.pop(users.index(client.user))
winner = random.choice(users)
await ctx.send(f'Congratulations {winner.mention} won **{prize}**! Hosted by {ctx.author.mention}')
except Exception as er:
await ctx.send(er)
您必须重命名您的time: int
参数,这样它就不会干扰time
模块。 鉴于上下文,我会建议类似timeUntil
的东西。
完整代码:
@client.command(description="Starts a giveaway.")
@has_permissions(manage_messages=True)
async def gstart(ctx, timeUntil: int, winners: int, *, prize: str):
global users, new_msg
try:
em = discord.Embed(
title=f"<a:fun:1052215771738165269> {prize} <a:fun:1052215771738165269>",
color=discord.Colour.random()
)
timestamp = time.time() + timeUntil
em.set_footer(text=f"Started by {ctx.author}")
em.add_field(name=f"** **", value=f"**Ends at**: <t:{int(timestamp)}:f> or <t:{int(timestamp)}:R> \n **Prize**: {prize} \n **Hosted by**: {ctx.author.mention}", inline=False)
my_msg = await ctx.send(embed=em)
await my_msg.add_reaction("🎉")
await asyncio.sleep(time)
new_msg = await ctx.channel.fetch_message(my_msg.id)
for i in range(winners):
users = [user async for user in new_msg.reactions[0].users()]
users.pop(users.index(client.user))
winner = random.choice(users)
await ctx.send(f'Congratulations {winner.mention} won **{prize}**! Hosted by {ctx.author.mention}')
except Exception as er:
await ctx.send(er)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.