[英]Discord bot is not finding channel by name
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.我正在制作一个 Discord 机器人,当它启动时,我让它搜索公会文本频道并检查特定的频道名称。 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.如果我打印出频道列表,它会找到所有频道,尽管如果我尝试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)
This is my code, and this is the output:这是我的代码,这是 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?你知道为什么它在 if 语句中不与 true 比较吗?
I suspect channel.name
is not of type str
, and thus is
evaluates to false.我怀疑channel.name
不是str
类型, is
评估为 false。 Try:尝试:
if str(channel.name) == "general":
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.