【发布时间】:2020-02-16 14:08:01
【问题描述】:
我正在制作一个 Discord 机器人,当它启动时,我让它搜索公会文本频道并检查特定频道名称。如果我打印出频道列表,它会找到所有频道,尽管如果我尝试 if channel.name is "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 进行比较吗?
【问题讨论】:
标签: python python-3.x discord discord.py