TypeError: ‘HistoryIterator’ object is not iterable

  discord.py, python

As you can see from the title, my discord.py bot is returning this error: TypeError: ‘HistoryIterator’ object is not iterable. I was just trying to code an "analyze" command (basically a command that goes through a user’s history and tells you about them). I’ve tried turning the channel variable into a string or a list but it didn’t work (the error said something about how the variable needs to be a string, or an integer or a byte-like object before you can turn it into str / int). I’ll paste the full code below.

def calcnm(user: discord.Member, channel: discord.TextChannel):
    channel = bot.get_channel(880123663318409277)
    global counter_calcnm
    counter_calcnm = 0
    for message in channel.history(limit=1000):
        if message.author == user:
            counter_calcnm = counter_calcnm + 1
    return counter_calcnm


@bot.command(pass_context = True)
async def analyze(ctx, user):
    logging = bot.get_channel(880123671430168646)
    await ctx.send("Analyzing " + str(user) + ", this may take a while")

    # Analyze Code Start
    status = await ctx.send("Initiating Code")
    await asyncio.sleep(1)

    await status.edit(content="Finding last message - BETA ()")

    await status.edit(content="Calculating the number of messages they've sent")

    await status.edit(content="Calculating account information")
    calcnm(user, 880123663318409277)
    guild = bot.get_guild(880108797820026881)
    if guild.get_member(int(user)) is not None: 
        isinserver = True
    else:
       isinserver == False
    
    # Analyze Code End
    await status.edit(content="Finished Analyzing")

    await ctx.send("Profile = " + str(user))
    await ctx.send("LM = Error")
    await ctx.send("MSGS = " + str(counter_calcnm))
    await ctx.send("CA = " + user.created_at.strftime("%d/%m/%Y %H:%M:%S"))
    await ctx.send("IIS = " + str(isinserver))

Source: Python Questions

LEAVE A COMMENT