Discord bot is not finding channel by name

Viewed 158

I am making a Discord bot and when it boots up I am having it search through the guilds text-channels and checking for a specific channel name. If I print out the list of channels, it finds all of them although if I try if channel.name is "general" it doesn't change the flag to true.

async def on_ready():
    print("Bot is ready.")
    has_channel = False
    for guild in client.guilds:
        for channel in guild.text_channels:
            print(channel.name)
            if channel.name is "general":
                has_channel = True
        print(has_channel)

This is my code, and this is the output :

Bot is ready.
general
streaming-updates
welcome
goodbye
streaming-schedules
False

Would you know why it isn't comparing to true on the if statement?

1 Answers

I suspect channel.name is not of type str, and thus is evaluates to false. Try:

if str(channel.name) == "general":
Related