Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord bot未按名称查找频道_Python_Python 3.x_Discord_Discord.py - Fatal编程技术网

Python Discord bot未按名称查找频道

Python Discord bot未按名称查找频道,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,我正在制作一个Discord机器人,当它启动时,我让它在协会的文本频道中搜索,并检查特定的频道名称。如果我打印出频道列表,它会找到所有频道,尽管如果我尝试如果channel.name为“general”它不会将标志更改为true async def on_ready(): print("Bot is ready.") has_channel = False for guild in client.guilds: for channel in guild.t

我正在制作一个Discord机器人,当它启动时,我让它在协会的文本频道中搜索,并检查特定的频道名称。如果我打印出频道列表,它会找到所有频道,尽管如果我尝试
如果channel.name为“general”
它不会将标志更改为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)
这是我的代码,这是输出:

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

你知道为什么它在if语句中没有与true进行比较吗?

我怀疑
频道。name
不是
str
类型,因此
is
的计算结果为false。尝试:

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

正是这样,我甚至尝试了
str(channel.name)的“general”:
但没有成功。谢谢你给我指出了正确的方向,我在一些文档中读到了
channel.name
是type
str
,但我想不是真的。再次感谢。