2

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?

Ruben-96
  • 67
  • 1
  • 6

1 Answers1

1

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

if str(channel.name) == "general":
Gavin Uberti
  • 393
  • 4
  • 8
  • 1
    exactly this worked, I even tried ```str(channel.name) is "general":``` but it didn't work. Thanks for pointing me to the right direction, I had read in some documentation that ```channel.name``` is type ```str``` but I guess not really. Thanks again. – Ruben-96 Oct 20 '19 at 05:04