Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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 如何检查消息是否在正确的通道中发送_Python_Discord - Fatal编程技术网

Python 如何检查消息是否在正确的通道中发送

Python 如何检查消息是否在正确的通道中发送,python,discord,Python,Discord,我希望我的discord机器人删除消息,如果它不在机器人命令频道中,但我不确定一件事。我试过: if message.channel==“bot命令” 及 如果message.channel==531183259250458636 但它们都不起作用。解决方案 如果message.channel.name==“bot命令” 为什么这样做 这是因为如果我们查看文档,我们可以看到message.channel返回TextChannel、DMChannel或GroupDMChannel。在您的情况下,它

我希望我的discord机器人删除消息,如果它不在机器人命令频道中,但我不确定一件事。我试过:

if message.channel==“bot命令”

如果message.channel==531183259250458636

但它们都不起作用。

解决方案
如果message.channel.name==“bot命令”

为什么这样做
这是因为如果我们查看文档,我们可以看到message.channel返回
TextChannel
DMChannel
GroupDMChannel
。在您的情况下,它将返回
textconnel
。如果我们查看
TextChannel
的属性,有一个名为
name
的属性,它是一个字符串。因此,我们可以将其与另一个字符串进行比较。

您正在查找
message.channel.name
message.channel.id