Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'bool' object is not iterable

Hi I'm having some issues with a bit of code which I'm getting a type error which is TypeError: 'bool' object is not iterable Should I be using an if state rather that a for statement?

What I'm trying to achieve is if on_message a message has been pinned for 7 days or more then unpin that message.

Here's what I'm working with:

async def on_message(self, message):
    """Listen for a message then unpin any other messages older than 7 days"""
    server = message.server
    channelid = '490899209067823135'
    limit_date = datetime.now() - timedelta(days=7)
    if server:
        for message.content in message.channel.id == channelid:
            if limit_date:
                try:
                    await self.bot.unpin_message(message)

                except discord.Forbidden:
                    print("No permissions to do that!")

Not sure where I'm going wrong here.

like image 443
Shan Jameson Avatar asked Mar 04 '26 05:03

Shan Jameson


1 Answers

In your for loop, message.channel.id == channelid evaluates to a boolean value either True or False. So your for loop becomes either

for message.content in True

or

for message.content in False

The right side of in here must be some iterable. The compiler complains because it isn't.

To suggest a solution to this problem, we need more information about what you are trying to do.

like image 166
Code-Apprentice Avatar answered Mar 06 '26 17:03

Code-Apprentice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!