Skip to content
Advertisement

Getting error – ‘int’ object has no attribute ‘time’

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)

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:

@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)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement