I'm trying to make a giveaway command for my bot but I get an error every time I try to run the command
'int' object has no attribute 'time'
My code for the giveaway command
@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)
You must rename your time: int
parameter, so it does not interfere with the time
module. Given the context, I would suggest something like timeUntil
.
Complete code:
@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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.