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
JavaScript
x
25
25
1
@client.command(description="Starts a giveaway.")
2
@has_permissions(manage_messages=True)
3
async def gstart(ctx, time: int, winners: int, *, prize: str):
4
global users, new_msg
5
try:
6
em = discord.Embed(
7
title=f"<a:fun:1052215771738165269> {prize} <a:fun:1052215771738165269>",
8
color=discord.Colour.random()
9
)
10
timestamp = time.time() + time
11
em.set_footer(text=f"Started by {ctx.author}")
12
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)
13
my_msg = await ctx.send(embed=em)
14
await my_msg.add_reaction("🎉")
15
await asyncio.sleep(time)
16
new_msg = await ctx.channel.fetch_message(my_msg.id)
17
for i in range(winners):
18
users = [user async for user in new_msg.reactions[0].users()]
19
users.pop(users.index(client.user))
20
winner = random.choice(users)
21
await ctx.send(f'Congratulations {winner.mention} won **{prize}**! Hosted by {ctx.author.mention}')
22
except Exception as er:
23
await ctx.send(er)
24
25
Advertisement
Answer
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:
JavaScript
1
24
24
1
@client.command(description="Starts a giveaway.")
2
@has_permissions(manage_messages=True)
3
async def gstart(ctx, timeUntil: int, winners: int, *, prize: str):
4
global users, new_msg
5
try:
6
em = discord.Embed(
7
title=f"<a:fun:1052215771738165269> {prize} <a:fun:1052215771738165269>",
8
color=discord.Colour.random()
9
)
10
timestamp = time.time() + timeUntil
11
em.set_footer(text=f"Started by {ctx.author}")
12
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)
13
my_msg = await ctx.send(embed=em)
14
await my_msg.add_reaction("🎉")
15
await asyncio.sleep(time)
16
new_msg = await ctx.channel.fetch_message(my_msg.id)
17
for i in range(winners):
18
users = [user async for user in new_msg.reactions[0].users()]
19
users.pop(users.index(client.user))
20
winner = random.choice(users)
21
await ctx.send(f'Congratulations {winner.mention} won **{prize}**! Hosted by {ctx.author.mention}')
22
except Exception as er:
23
await ctx.send(er)
24